Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects parentFolder, script fix

  • parentFolder, script fix

  • Timur Solomon

    May 16, 2022 at 5:19 pm

    Hi everyone, I’m writing a script and I want the created composition to be moved to an already created folder.

    My code is not working

    for (var i = 1; i <= app.project.numItems; i++) {
    var comp = app.project.item(i);
    if (comp.name == "pMedia" && comp instanceof FolderItem) {
    var pMedia = app.project.item(i); // Find Parent Folder
    };
    var pComp = app.project.items.addComp("pComp", 1920, 1080, 1, 15, 30); // Create Comp
    pComp.parentFolder = pMedia; // What's wrong here?
    }

    Can you point out my mistake?

  • Walter Soyka

    May 17, 2022 at 2:39 am

    Yes — your indentation is deceptive. You are creating pComp and attempting to move it to pMedia inside your loop. Unless the pMedia folder is the very first item in the project, this will fail; creating pComp needs to happen outside the loop, after you’ve identified the pMedia folder.

    See this revision. (I’ve also renamed your ‘comp’ variable, because reading ‘comp instanceof FolderItem’ made me do a double-take, I’ve added a little error checking in case the folder isn’t found, and I’ve added comments to explain what’s going on throughout.)

    app.beginUndoGroup("Create pComp in pMedia");
    // create a variable to store our media folder
    var pMedia = null;
    // step through the project, looking for the pMedia folder
    for (var i = 1; i <= app.project.numItems; i++) {
    var projectItem = app.project.item(i);
    // check the current project item to see if it's a folder named 'pMedia'
    if ((projectItem.name == "pMedia") && (projectItem instanceof FolderItem)) {
    // we found it, so let's store it in pMedia, then stop processing the loop
    pMedia = projectItem;
    break;
    };
    }
    // if we failed to find a pMedia folder, tell the user
    // otherwise, create a new comp and put it in the pMedia folder
    if (pMedia == null) {
    alert("No pMedia folder found!");
    } else {
    var pComp = app.project.items.addComp("pComp", 1920, 1080, 1, 15, 30); // Create Comp
    pComp.parentFolder = pMedia;
    }
    app.endUndoGroup();
  • Timur Solomon

    May 17, 2022 at 3:01 am

    Hi Walter,

    Thanks for your reply.

    The most valuable thing is that you explained to me that it didn’t have to be done in a loop. I figured out what the script logic error is.

Viewing 1 - 3 of 3 posts

Log in to reply.

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