Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

comp importing script not working properly

Community Beginner ,
Mar 05, 2023 Mar 05, 2023

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();
}
};

TOPICS
Import and export , Scripting
395
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2023 Mar 05, 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().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 05, 2023 Mar 05, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2023 Mar 05, 2023
LATEST

Exactly. Unless it's the active item.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines