add local file to selected comps

What type of scripts do you need?

Moderator: byronnash

Post Reply
render_wander
Posts: 1
Joined: January 12th, 2023, 11:14 am

Hello!

I am trying to add a local file to selected comps, fit it to width, then make it a guide layer all at once - is this possible?

Thank you!
Greg

Kasio
Posts: 10
Joined: February 8th, 2008, 4:39 am

Code: Select all


function importGuide() {
  var comps = app.project.selection;

  var myFile, i, myItem, comp, myLayer;

  var myFilePath = ''; // insert path here or..
  if (myFilePath) {
    myFile = new File(myFilePath);
  } else {
    myFile = File.openDialog(); // ..select file instead
  }

  var importedFile = app.project.importFile(new ImportOptions(myFile));

  // Find the item number of the imported file
  for (i = 1; i <= app.project.numItems; i++) {
    if (app.project.item(i).name === importedFile.name) {
      myItem = i;
      break;
    }
  }

  for (i = 0; i < comps.length; i++) {
    comp = comps[i];

	// Open comp in order for Fit to Comp To Work
	comp.openInViewer();

    // If found add item to comp
    if (myItem) {
      myLayer = comp.layers.add(app.project.item(myItem));
    }

    // Fit to comp width
    app.executeCommand(app.findMenuCommandId('Fit to Comp Width'));

    // Make guide layer
    myLayer.guideLayer = true;
  }
}

importGuide();


Post Reply