Item : by name ?

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
golgo
Posts: 2
Joined: August 2nd, 2007, 3:11 am

Hello there, first post for me :)

The only way to manipulate an Item seems to call it by its index, that represents his alphabetic position in all the project's items, right ???

Is there a way to call an item (a comp for exemple) by it's name, like for a layer ?

The use of item index is not fair, like when you import a new item, the rank and so the index changes...

thanx for your lights !
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

You can reference by name, like so...

Code: Select all

var myComp = app.project.activeItem;  //NOTE comp must be selected in the project window.
var AudioAmplitudeLayer = myComp.layer("Audio Amplitude"); 
Audio Amplitude is the name of a layer in my comp.

Now you can refference properties of the layer like so...

Code: Select all

t=AudioAmplitudeLayer.inPoint;
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

I think Golgo was asking if you could reference a comp by name, in the same way as you can with a layer. I think the only way is to create a loop that goes through all the items, checking for the correct name. Not so bad really.
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

So,

Does app.project have a count?
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

app.project.numItems

Dan
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

So I guess to scan the project window you could...

Code: Select all

n = app.project.numItems;
for (m=1; m<n; m++;)
{
if (app.project.item(m).name =="Label I am Searching For")
{
//I have found an item in the project window by name.
}
}
Last edited by Atomic on August 6th, 2007, 5:58 am, edited 1 time in total.
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

Index starts at 1 (not 0) for project items.
golgo
Posts: 2
Joined: August 2nd, 2007, 3:11 am

Atomic wrote:So I guess to scan the project window you could...

Code: Select all

n = app.project.numItems;
for (m=1; m<n; m++;)
{
if (app.project.item(m).name =="Label I am Searching For")
{
//I have found an item in the project window by name.
}
}
Ok, that works fine. But my goal is to select a comp, so how can I do it ? (activeItem is read only)

Thanx !
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

m <= n , unless you want to skip the last item !

when you have retrieved the item (in a variable), do whatever you want with it (add layers, change settings...)

the scripting guide is a good way to start :wink:
)orgen
Posts: 34
Joined: August 28th, 2006, 4:12 am

maybe I don't fully understand the question, but you can at least reference a layer in a specific comp like this:

amp=comp("intro").layer("control").effect("amplitude")("Slider");
Post Reply