Page 1 of 1

How to set a reference to compositions name instead of index

Posted: May 9th, 2012, 12:50 am
by Andres
I need to work with some variables contained in the first layer of a precomp in order to move some of the in-out points of the in my main comp.

When working with Expressions I was able to reference the comp's name directly using [comp("comp name")
But the same method doesn't seem to apply for scripting.
And the current item and selected item won't get me where i need to go as I need to get values from many precomps.

This is what I'm trying to to do

Code: Select all

Vid1Dur = comp("Put 1st video here").layer(1).outPoint; //gets precomps 1st layers length by retrieving the outpoint
Thanks everyone. I'm looking forward to learn and help as my skills improve.

Re: How to set a reference to compositions name instead of i

Posted: May 9th, 2012, 10:33 am
by Dan Ebberts
If you want to find a comp by name, you have to loop through the project items, like this:

Code: Select all

var theComp = null;
var theName = "Put 1st video here";
for (var i = 1; i <= app.project.numItems; i++){
	if (app.project.item(i) instanceof CompItem && app.project.item(i).name == theName){
		theComp = app.project.item(i);
		break;
	}
}

// test for theComp == null
Dan