Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Problem wit for loop in Extendscript

  • Problem wit for loop in Extendscript

    Posted by Riaan Myburgh on September 5, 2017 at 1:07 pm

    Hi,
    I am very new to extendscript/javascript and realise theres probably an easy solution here.
    My objective is to be able to import footage into AE, then run a script that counts the number of files available, and creates a corresponding comp from each footage file.(each ones specific parameters), and then to place the file inside the comp .

    Here is the code


    var proj = app.project ;

    var newCompsToMake = proj.numItems;

    app.beginUndoGroup("Add5Comps");
    for (var i = 1; i <= newCompsToMake; i++){
    proj.item(i).width

    var newCompWidth = proj.item(i).width;
    var newCompNames = proj.item(i).name;
    var newCompHeight = proj.item(i).height;
    var newCompPAR = proj.item(i).pixelAspect;
    var newCompDur = proj.item(i).duration;
    var newCompFPS = proj.item(i).frameRate;

    proj.items.addComp(newCompNames, newCompWidth, newCompHeight, newCompPAR, newCompDur, newCompFPS);

    };
    app.endUndoGroup();

    So in typing this I realise the problem is that each time a new comp is created it replaces the previous index, thus all the comps are being made from the same footage file.
    Any ideas on how to remedy this are welcome!

    Walter Soyka replied 8 years, 12 months ago 2 Members · 1 Reply
  • 1 Reply
  • Walter Soyka

    September 6, 2017 at 1:07 pm

    Instead of looping through every item in the project and creating comps in the same loop, split this into two loops. The first loop should step through every item in the project, building an array of footage objects to be processed. The second loop should step through the array you just built.

    Walter Soyka
    Designer & Mad Scientist at Keen Live [link]
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy