Highlighted

New help with a simple script

Explorer ,
Oct 13, 2020

Copy link to clipboard

Copied

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();

 

TOPICS
Expressions, How to, Scripting

Views

75

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

New help with a simple script

Explorer ,
Oct 13, 2020

Copy link to clipboard

Copied

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();

 

TOPICS
Expressions, How to, Scripting

Views

76

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 13, 2020 0
Engaged ,
Oct 14, 2020

Copy link to clipboard

Copied

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"

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 0
Explorer ,
Oct 14, 2020

Copy link to clipboard

Copied

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'",
	

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 0
Engaged ,
Oct 14, 2020

Copy link to clipboard

Copied

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';

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 0
Explorer ,
Oct 14, 2020

Copy link to clipboard

Copied

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';

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 0
Engaged ,
Oct 14, 2020

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 0
Explorer ,
Oct 14, 2020

Copy link to clipboard

Copied

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();

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 0
Engaged ,
Oct 14, 2020

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 1
Explorer ,
Oct 14, 2020

Copy link to clipboard

Copied

Yay! Got it! Thanks so much Peter!

I'm sure there would be more "checks" a pro coder would add but this is just for me to automate and setup things faster and I'll just have to remember how to use them. 

I've got a good template now and learned probably enough to create more similar scripts.

Cheers! 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 0
Community Beginner ,
Oct 15, 2020

Copy link to clipboard

Copied

Have you had a look at Animation Presets?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 15, 2020 0