Skip to main content
Participant
March 12, 2013
Question

Reference item by ID

  • March 12, 2013
  • 1 reply
  • 1249 views

I'm working on a project where I need to be able to reference compositions by their unique ID attribute.

Is there a way to reference to an item in a project based on its ID without having to do a billion if check loops

to see if the ID matches?

Something similar to how you can reference layers by name.

app.project.activeItem.layer("playerItem")

Something like

ID = app.project.activeItem.id

app.project.items(ID)

would be ideal but that doesnt seem to work.

This topic has been closed for replies.

1 reply

Lazlo_Hollyfeld
Inspiring
March 12, 2013

Once you find the composition in the loop, store it in a variable, then use that variable throughout the rest of your script.

Dimn7211Author
Participant
March 12, 2013

I ended up creating a recursive function in order to locate the comp base on its id. Here's my final working function:

function findXmpComp(id){

    function digForComp(folder, id){

    var foundComp;

    var currentFolder = folder;

        for(var i=1; i<= currentFolder.items.length;i++){

            if(currentFolder.items.id == id){

                foundComp = currentFolder.items;

                return foundComp;

            }

            if(currentFolder.items.typeName == "Folder"){

                foundComp = digForComp(currentFolder.items, id);

            }

        }

        if(foundComp == null){

            return null;

        }else{

            return foundComp;

        }

    }

    var foundComp = digForComp(app.project, id)

    if(foundComp == null){

        alert("Missing Comp");

    }

    return foundComp;

}

Jeff Almasol
Adobe Employee
Adobe Employee
September 13, 2013

Just curious... are you storing that comp id external to the project, i.e., that id would need to be the same between AE sessions? Or are you just using the id value within the same AE session?

Jeff