comp importing script not working properly
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();
}
};