Skip to main content
Participant
March 5, 2023
Question

comp importing script not working properly

  • March 5, 2023
  • 1 reply
  • 490 views

hello guys, i am trying to make an extension to import project and add its comp to the timeline, however it only works well when i select the timeline or comp panel, if project panel is selected it import the project without adding its comp to my timeline.. any help will be appreciated , thanks..

here is my code 


function Generate() {

// Get a reference to the current project
var project = app.project;


// Specify the path to the project file containing the composition you want to import
var filePath = "C:/Users/mhmood/Documents/test.aep";


// Import the project file and get a reference to the imported project item
var importedProjectItem = project.importFile(new ImportOptions(File(filePath)));


// Get the first composition in the imported project
var importedComp = importedProjectItem.item(1);

// Create a new layer for the imported composition
var layer = app.project.activeItem.layers.add(importedComp);

// Set the in and out points of the layer to match the duration of the current composition
layer.startTime = project.activeItem.time;

}

 

$._ext = {
generateComComp: function() {
Generate();
}
};

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
March 5, 2023

This line:

var layer = app.project.activeItem.layers.add(importedComp);

expects that you have a comp opened as the active item. I'm not sure what the alternative is. If you know the name of the comp, I guess you could find that comp in the project bin and do comp.openInViewer().

Participant
March 6, 2023

the comp is opened but the script doen't recognize it as open unless the copm panel is selected

Dan Ebberts
Community Expert
Community Expert
March 6, 2023

Exactly. Unless it's the active item.