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

You'd think I'd figured it out but no. I'm useless. 

I tried every possibilities you  mentionned it stops at the first line.

 

app.beginUndoGroup("MDV 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/MDV Sliders.ffx");

if (thePreset.exists == true) {
	myNull.applyPreset(thePreset);
} else {
	alert("no preset found at specified path");
    
}  
   
    var myLayer = myComp.layer(2);
    
         myLayer.property("Transform").property("X Position").expression = 'transform.xPosition+thisComp.layer("Sliders").effect("X Axis")("Slider")*index';
         myLayer.property("Transform").property("Y Position").expression = 'transform.xPosition+thisComp.layer("Sliders").effect("Y Axis")("Slider")*index';
         myLayer.property("Transform").property("Z Position").expression = 'transform.xPosition+thisComp.layer("Sliders").effect("Z Axis")("Slider")*index';
         myLayer.property("Transform").property("X Rotation").expression = 'transform.xRotation+thisComp.layer("Sliders").effect("X Rotation")("Slider")*index';
         myLayer.property("Transform").property("Y Rotation").expression = 'transform.xRotation+thisComp.layer("Sliders").effect("Y Rotation")("Slider")*index';
         myLayer.property("Transform").property("Z Rotation").expression = 'transform.xRotation+thisComp.layer("Sliders").effect("Rotation")("Slider")*index';
         
         app.endUndoGroup();

 


Make sure 'Enable Javascript Debugger' is turned on in the prefs so you get some useful error messages.

When I Tried it said "Can not set expression with this property, because the property or parent property is hidden"

 

In order to access the separate X,Y, Z Position properties that layer (layer 2, the layer that would be layer 1 before you run the script) needs to be a 3D layer where you've right-clicked on the Position property and chosen Separate Dimensions.

 

Or you can put this between defining myLayer and adding the expressions:

myLayer.threeDLayer = true;
myLayer.property("Transform").property("Position").dimensionsSeparated = true;
 
There are all kinds of safeguards you would ideally add (especially if anyone else will be using the script). Is a comp selected, are there any layers, are they the right kinds of layers, etc.