createMoveAction

Hello,

How do I use the ‘createMoveItemAction’ to move a project item into a bin?

I’m a beginner at UXP. :slightly_smiling_face: I have a test project in Premiere set up with a ‘test_video_.mov’ and ‘test_bin_’ in the project panel. I select the video and then the bin, and try to use the code below. I’m using the UDT, testing this with a plugin created using the ‘quick-starter’ template. I’m not seeing any error messages in the debug console, but the footage isn’t moving into the bin.

Here is the code I’m using:

const ppro = require("premierepro");

async function actions() {
  try {
    const project = await ppro.Project.getActiveProject();
    const projectSelection = await ppro.ProjectUtils.getSelection(project);
    const projectSelectedItems = await projectSelection.getItems();
    const rootItem = await project.getRootItem();
    const footage = await projectSelectedItems[0];
    console.log(footage);
    const bin = await projectSelectedItems[1];
    console.log(bin);
    const moveAction = rootItem.createMoveItemAction(footage, bin);
    executeAction(project, moveAction);

  } catch(e) {
    console.log(e);
  }
}

function executeAction(project, action) {
  try {
    project.lockedAccess(() => {
      project.executeTransaction((compoundAction) => {    
        compoundAction.addAction(action);
      });
    });
  } catch (err) {
    console.log(`Error: ${err}`);
  }
}

document
  .querySelector("#btnPopulate")
  .addEventListener("click", actions);

Thank you so much for any thoughts you might have!

Hi!

Second parameter of createMoveItemAction() is expected to be a FolderItem, while the item from projectItemSelection is ProjectItem.

Using

const moveAction = rootItem.createMoveItemAction(footage, ppro.FolderItem.cast(bin));

should fix the issue you are seeing.

Also please note that it’s best practice to create action inside of project.lockedAccess() block to avoid hitting asserts.

Thanks for trying out UXP!

Thank you so much! It’s working now.

Also, I placed the create action inside of a project.lockedAccess() block as you suggest. Not sure if I have it organized correctly or not, or if there would be a better way to set this up. I have my updated code below.

Thank you for the help, I appreciate it!

const ppro = require("premierepro");

//select footage first, then select bin second
async function actions() {
  try {
    const project = await ppro.Project.getActiveProject();
    const projectSelection = await ppro.ProjectUtils.getSelection(project);
    const projectSelectedItems = await projectSelection.getItems();
    const rootItem = await project.getRootItem();
    const footage = await projectSelectedItems[0];
    const bin = await projectSelectedItems[1];
      project.lockedAccess(() => {
      const moveAction = rootItem.createMoveItemAction(footage, ppro.FolderItem.cast(bin));
      executeAction(project, moveAction);
      });  
  } catch(e) {
    console.log(e);
  }
}

function executeAction(project, action) {
  try {
    project.lockedAccess(() => {
      project.executeTransaction((compoundAction) => {    
        compoundAction.addAction(action);
      });
    });
  } catch (err) {
    console.log(`Error: ${err}`);
  }
}

//‘quick-starter’ template.
document
  .querySelector("#btnPopulate")
  .addEventListener("click", actions);
1 Like