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

Thanks so much for the detail info Peter. I'm very close I think.

I added these lines (I used the script to get the property info). I put my expression in single quotes but it stops at the first line. I fiddle with it for an hour trying to refer to the layer by name, id etc. it didn't work either. Anything obvious I'm missing?

 

         layer(2).property("Transform").property("X Position").expression = 'transform.xPosition+thisComp.layer("Sliders").effect("X Axis")("Slider")*index';
         layer(2).property("Transform").property("Y Position").expression = 'transform.xPosition+thisComp.layer("Sliders").effect("Y Axis")("Slider")*index';
         layer(2).property("Transform").property("Z Position").expression = 'transform.xPosition+thisComp.layer("Sliders").effect("Z Axis")("Slider")*index';
         layer(2).property("Transform").property("X Rotation").expression = 'transform.xRotation+thisComp.layer("Sliders").effect("X Rotation")("Slider")*index';
         layer(2).property("Transform").property("Y Rotation").expression = 'transform.xRotation+thisComp.layer("Sliders").effect("Y Rotation")("Slider")*index';
         layer(2).property("Transform").property("Z Rotation").expression = 'transform.xRotation+thisComp.layer("Sliders").effect("Rotation")("Slider")*index';

 

 


You can start from "myNull.property...." because you already defined that when that layer was created (i.e. myNull represents that null layer object), but if you want to access a different layer you'll need to start from the comp object. layer(2) on its own is meaningless.

 

myComp.layer(2).property("Tran.....

 

which you can also think of as:

app.project.activeItem.layer(2).property("Tran.....

 

or you could do:

var myLayer = myComp.layer(2);

myLayer.property("Tran.....

 

or you could even do:

var MyLayer = myComp.layer(2);

var MyTransform = MyLayer.property("Transform");

MyTransform.property("X Position").....

 

Hopefully you get the idea!