precompose function is undefined? what the?

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

since my last post where i figured out how to get a script to take a trimmed layer and precomp it so that the duration of the precomp was exactly equal to the length of the layer after trimming, i'm having trouble getting the next part of my script to work.

i want to take this layer (which is now a precomp) and precomp it. :)

//select layerComp layer in the timeline
//given myComp is the active comp item
//and layerComp is a precomp within myComp

//select the correct layer to precomp in the timeline:

var myNewLayers = myComp.layers;
var newChosenLayer = myNewLayers.byName(layerComp.name);
newChosenLayer.selected = true;

alert(newChosenLayer.name); //so i can tell it's selecting the correct one

var layerIndices = new Array();
for (var i = 0; i < newChosenLayer.length; i++)
{
layerIndices[layerIndices.length] = newChosenLayer.index;
}

var shadedComp = newChosenLayer.precompose(layerIndices, Name, false);


i keep getting an error saying the the precompose function is undefined, and i can't figure out why, as it looks legal to me.

any clues?
thanks guys.
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

so it works if i write
myComp.layers.precompose

instead of
newChosenLayer.precompose

and I don't understand why this is, as the variable "newChosenLayer" was supposed to represent myComp.selectedLayers.

surely it's the same thing? and yet one works and the other does not...

i was avoiding using myComp.layers.precompose because it looks (the way the code is written) that i want to precompose all layers in myComp.

hmmm but i think i understand now. it's saying in the comp myComp, precompose layers(which layers, name of the new comp, move all attributes).
right.

i thought all i had to do was say "precompose my selected layers(they have these indices, name of comp, move attributes)".

guess i need more practice translating the commands into english. :)
vidpat
Posts: 86
Joined: October 21st, 2004, 12:36 am
Location: Phoenix, AZ
Contact:

precompose() is a method of LayerCollection. In the first post, newChosenLayer is set to the result of <LayerCollection>.byName(), which is a Layer object. Thus, you are calling precompose() on a Layer, not a LayerCollection, hence the error.

In the second post: Although selectedLayers represents a collection of layers, it is not of type LayerCollection, rather just an Array. Thus, <Array>.precompose() is undefined, as well.
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

thanks for clearing that up so succinctly. vidpat. that makes a lot of sense, esp the bit about the arrays vs layer collections.

except that to my mind, i would interpret a layer object still to be a collection of layers, it's just a collection of one instead of many. heh, as i said, need more practice interpreting things! :) time for me to rtfm again.
vidpat
Posts: 86
Joined: October 21st, 2004, 12:36 am
Location: Phoenix, AZ
Contact:

I think I understand what you are saying. For nested comps, that is how it appears in the UI. However, thing are a bit more complicated internally, which is reflected in the scripting API.

A nested comp is just an instance of the comp item (think of it in the Project Window), which itself owns a LayerCollection of the layers in that comp.

So, to access the layers of a nested comp, starting with the comp-layer in a different comp, something like this would be needed:

Code: Select all

<Layer>.source.layers
Where <Layer> is a reference to the layer object in the current comp. Using the source attribute, we retrieve a reference to the CompItem representing the nested composition, from which we can retrieve its LayerCollection.
Post Reply