Skip to main content
ironchef_marc
Inspiring
October 13, 2020
Question

New help with a simple script

  • October 13, 2020
  • 2 replies
  • 1350 views
I wish AE had an easy way to create scripts for non-coders like recording Actions in PS and facilitate automation for repeated tasks..
I'm trying to write a script that would create a Null layer, load an Effect preset on it (a bunch of sliders)  and put in expressions in various parameters (X,Y, Z, position and X, Y, Z rotation) of the selected layer when the script was run (not the Null layer)?
I've figured out how to the Null layer, name it and apply my preset but I can't figure out how to do the rest. Any help would be appreciate as I'm not a coder.
Thanks!
My script so far.
 

 

app.beginUndoGroup("My Script");
    var myComp = app.project.activeItem;

    var myNull = myComp.layers.addNull(myComp.duration);

    myNull.name = "Sliders";
        
    var thePreset = new File("/Users/me/Documents/Adobe/After Effects 2020/User Presets/Sliders.ffx");

if (thePreset.exists == true) {
	myNull.applyPreset(thePreset);
} else {
	alert("no preset found at specified path");
    
}    
         
     
   app.endUndoGroup();

 

This topic has been closed for replies.

2 replies

Guido Eijrond
Inspiring
October 15, 2020

Have you had a look at Animation Presets?

Inspiring
October 14, 2020

So it's just adding the expressions to the slider properties you haven't worked out?

I'd recommend using this script to get a better understanding of the various ways to access a property through scripting. Select a property in the timeline and it will tell you the code needed to access it.

http://www.redefinery.com/ae/view.php?item=rd_GimmePropPath

 

Then it's really just a case of adding expressions using:

property.expression = "my expression here"

ironchef_marc
Inspiring
October 14, 2020

Thanks for the info.  I need to put in this expression in the X axis of the currently selected layer, linking it to a slider in the Null layer my script just created.

transform.xPosition+thisComp.layer("Controller").effect("X Axis")("Slider")*index

I need to do this for six sliders.

 

Not being a programmer I have no idea how to use that reference code.The instructions says one can use single property or property group so just adding that bit of code below? Where would I put the property.expression ? I also need to assign the X, Y, Z postion but I don't see it in the list, just position. 

property.expression = "transform.xPosition+thisComp.layer("Controller").effect("X Axis")("Slider")*index" 

 

 

		"ADBE Position":													"'.position'",
		"ADBE Scale":													"'.scale'",
		"ADBE Orientation":											"'.orientation'",
		"ADBE Rotate X":												"'.xRotation'",
		"ADBE Rotate Y":												"'.yRotation'",
																				// Handle 3D vs. 2D layers
		"ADBE Rotate Z":												"(prop.propertyGroup(prop.propertyDepth).threeDLayer || (prop.propertyGroup(prop.propertyDepth).property('intensity')!=null) || (prop.propertyGroup(prop.propertyDepth).property('zoom')!=null)) ? '.zRotation' : '.rotation'",
	

 

Inspiring
October 14, 2020

So let's just use the example of a Gaussian Blur effect applied to a layer. Obviously your preset will have different property names but the rules are the same.

 

I twirl open the layer in the timeline, twirl open the effect, etc and select the Gaussian Blur > Blurriness property, then having run the GimmePropPaths script I click its 'Get Property Path' button. It defaults to showing the path using the application as root so it shows:

 

app.project.item(1).layer("Pale Gray-Royal Blue Solid 1").property("ADBE Effect Parade").property("ADBE Gaussian Blur 2").property("ADBE Gaussian Blur 2-0001")

 

But you already have the comp (activeItem) and the layer (MyNull) so you just need everything after the layer....

 

myNull.property("ADBE Effect Parade").property("ADBE Gaussian Blur 2").property("ADBE Gaussian Blur 2-0001").expression = "your expression here";

 

Those properties are referenced by what are called 'matchnames' which are the internal, non-language specific names, so it would work no matter what language you were running AE under or if you've renamed things like effects. If you choose 'names' instead in GimmePropPaths you'll get something a bit more recognisable to work with, which should show it's not that diffcult to understand how to construct the path to a property.

 

myNull.property("Effects").property("Gaussian Blur").property("Blurriness").expression = "your expression here";

 

Some properties like Effects can hold any number of other property groups, i.e. multiple different effects...so for those you can reference what is inside them by index rather than name, like for instance the first effect on the layer:

 

MyNull.property("Effects").property(1).property("Blurriness").expression = "your expression here";

 

When adding the expression, be aware that strings (i.e. text) need to be wrapped in either 'single' or "double" quotes, but say if your expression string already has double quotes inside it, you'll need to wrap it in single quotes, otherwise it will think the string ends at the next instance of a double quote and  then most likely cause an error when it fails to understand what all the rest of the stuff is.

 

myNull.property("Effects").property("Gaussian Blur").property("Blurriness").expression = 'my expression "here" using all the "double quotes" I want because I'm wrapped in single quotes';