Skip to main content
tomia46669570
Known Participant
May 12, 2015
Question

Getting the Index of a Project Item to Use in Scripting Commands

  • May 12, 2015
  • 2 replies
  • 3776 views

Hello Everyone,

I'm interested in figuring out the best way to get the index of a Footage Item or a Comp. Is the only way to do that by searching through the entire library of items searching for a match using the name attribute?

Also, what's the difference between the index of an item and the id of an item?

Thanks in advance!

Tomi

This topic has been closed for replies.

2 replies

Dan Ebberts
Community Expert
Community Expert
May 12, 2015

Unfortunately, you can't access an item directly by name, so to get the item's index from its name, you'd need to loop through the item collection until you find an item of the correct type with the correct name. I don't think I ever use an item's index--I find it by name and then save the item in a variable.

Dan

tomia46669570
Known Participant
May 12, 2015

Hello Again Dan,

I appreciate the explanation!

When you describe looping through the item collection, do you mean all the items in the project?

Does that take a lot of processing power to accomplish?

I'm guessing that looking for the correct type AND the correct name at the same time, might cut down on how long it takes to get the index.

Do you mind showing me or linking me to an example of what it looks like to find the item's index via a name match and save it into a variable?

Thank you so much for your help!

Tomi

tomia46669570
Known Participant
May 12, 2015

I'm guessing i need to use a counter, an if/then case, and a break..

Will also try to figure this out...

: ]

Mathias Moehl
Community Expert
Community Expert
May 12, 2015

Not sure I understand your question, but an item is an item, no matter whether you get it from a layer or from your project panel.

var someItem = app.project.items[0];

var anotherItem = myComp.layer[0].source;  // the footage item of a layer in a comp (assuming the layer is an AV layer);

var thirdItem = myComp; // compItem is an AVItem is an Item

var idOfSomeItem = someItem.id;

var idOfAnotherItem = anotherItem.id;

var idOfThirdItem = thirdItem.id;

layer.index and layer.source.id are two very different things.

layer.index is the index of the layer in the composition, id is the unique id of its footage item.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
tomia46669570
Known Participant
May 12, 2015

Thanks, Mathias!

Sorry if the question was confusing. I was talking about the item object specifically and how to get the correct value needed to fill commands like these ones:

app.project.item(index).layers.add(item, duration)

layerCollection.add(anAVItem);

Nevertheless, I appreciate learning from what you wrote and described!