Copy n effects off of a source layer onto target layers?

What type of scripts do you need?

Moderator: byronnash

Post Reply
futurestack
Posts: 6
Joined: April 21st, 2008, 8:35 am

Hello all - I was wondering if you knew a robust way to use a script to copy effects(including keyframes) from a template layer onto a number of target layers. I have been fiddling with CreateLinkedEffects but I seem to butt my head up against how to create or manipulate arrays of effects, or even applying one set from a custom layer. Many of the examples I've been able to find only refer to built in ae effects like myLayer.addProperty("Levels")

I took a look at animation presets but it seems like overkill to use menu commands to save and load them, after all that gets into file I/O.

Pseudocode for what I'd like to get working would be like this:

Locate "TemplateComp"
Find "FXLayer"
Copy any effects from FXLayer into an array
Copy properties and keys into a subarray
Apply all effects in the array to all selected layers in a different comp
Apply properties and keys to new effects on each layer.
Adjust properties of the effects to be relevant to the target layers (for example, perhaps a Bulge Center property)

I have all of this up and running except for how to copy these pesky effects. There seems to be something fundamental I don't understand about how to address properties.

This code works:

Code: Select all

 var growEffect = FXLayer.effect(1); 
but this doesn't:

Code: Select all

for ( var i = 0 ; i < FXLayer.Effects.length; i++ )
{
  myEffect = FXLayer.Effects;
  myEffectArray[myAffectArray.length] = myEffect;
}
because FXLayer.Effects.length returns an undefined. I've tried many other syntaxes as well with no luck. Does anyone have a sample script that does something like this that I could take a look at, or at least a nudge in the right direction? Thanks in advance.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Effects is a PropertyGroup object, so you would use FXLayer.Effects.numProperties
futurestack
Posts: 6
Joined: April 21st, 2008, 8:35 am

ah, this brings the issue that I had encountered but didn't remember at the time of writing my original post. When I try to then assign an effect from my array onto the target layer it gives me 'After Effects error: Can not add a property with name "[object PropertyGroup]" to this PropertyGroup'. I also tried assignment but addressing effects on a target layer appears to be read only. Here are those couple of things:

Code: Select all

for( f = 0; f < effectArray.length; f++ )
{
	theLayer("Effects").addProperty(effectArray[f]);
	//theLayer.effect(f) =  effectArray[f]; 	
}
sorry if I'm missing something basic...
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Your effectArray contains references to the existing effect objects, but when you add an effect you do so by using it's name or matchName. You can't add the existing effect object again, but you can add a new copy of an effect with the same name.

theNewEffect = theLayer("Effects").addProperty(effectArray[f].matchName);
futurestack
Posts: 6
Joined: April 21st, 2008, 8:35 am

Interesting. So the effect property group in essence doesn't have a copy constructor, the only way to do what I'm talking about is to create a 3 dimensional array of attributes? or custom datatype? and manually inscribe and then reassign all the data?

layer -> [ effect ][ effectproperties ][ keyframes / expression ]

That seems fantastically inconvenient for what should be such a simple task.

[edit: overuse of "seems"]
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

You're right, it's not great. And you can't copy custom data types (i.e. Levels). You'll need to go through checking the PropertyValueType's, e.g. if (effectProperty.propertyValueType != PropertyValueType.CUSTOM_VALUE).
Post Reply