ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Scripting - Add to Essential Graphics Panel

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kevin Snyder
Scripting - Add to Essential Graphics Panel
on Mar 28, 2020 at 9:07:07 pm

I'm trying to use this code to write a script so that I can add properties to the Essential Graphics Panel. Here's the reference code.

app.project.item(index).layer(index).propertySpec.addToMotionGraphicsTemplate(comp)

I came up with this, but I'm totally new at this, so I might be completely off.

app.beginUndoGroup("Add to EGP");

function add(){
var compName = app.project.activeItem.name;
var myLayer = app.project.activeItem.selectedLayers[0];
var propertySpec = myLayer.opacity;
propertySpec.addToMotionGraphicsTemplate(compName);

}

add()

app.endUndoGroup();


I received this error message when I run it.

"Unable to execute script at line 7. After Effects error: Unable to call "addToMotionGraphicsTemplate" because of parameter 1. Comp 1 is not of the correct type."


Return to posts index

Dan Ebberts
Re: Scripting - Add to Essential Graphics Panel
on Mar 28, 2020 at 10:03:07 pm

I haven't tried addToMotionGraphicsTemplate(), but my guess is that you need to provide it a comp object, not a comp name. Try that.

Dan



Return to posts index

Kevin Snyder
Re: Scripting - Add to Essential Graphics Panel
on Mar 30, 2020 at 7:54:57 pm

Thanks, Dan. I appreciate it. After some trial and error, I finally have a working script. The current version will add the selected layer's position to the Essential Graphics Panel. How do I make it run on all selected layers and not just the first one?

app.beginUndoGroup("Add to EGP");

function add(){

var myComp = app.project.activeItem; //Active comp
var selectProp = myComp.selectedLayers[0].position; //Position on selected layer;
var myLayer = myComp.selectedLayers[0].name; //Get layer name;
var myProp = "Position"; //Property name;
var myControl = myProp + " " + "-" + " " + myLayer;//Combine property name and layer name
selectProp.addToMotionGraphicsTemplateAs(myComp, myControl); //Add property to EGP and rename;
app.project.activeItem.motionGraphicsTemplateName = "Master Properties"; //Set template name;
myComp.openInEssentialGraphics(); //Opens comp in essential graphics panel;

}

add()

app.endUndoGroup();



Return to posts index


Dan Ebberts
Re: Scripting - Add to Essential Graphics Panel
on Mar 30, 2020 at 8:50:34 pm

I haven't tested this, but something like this:


app.beginUndoGroup("Add to EGP");

function add(theLayer){

var myComp = app.project.activeItem; //Active comp
var selectProp = theLayer.position; //Position on selected layer;
var myLayer = theLayer.name; //Get layer name;
var myProp = "Position"; //Property name;
var myControl = myProp + " " + "-" + " " + myLayer;//Combine property name and layer name
selectProp.addToMotionGraphicsTemplateAs(myComp, myControl); //Add property to EGP and rename;
app.project.activeItem.motionGraphicsTemplateName = "Master Properties"; //Set template name;
myComp.openInEssentialGraphics(); //Opens comp in essential graphics panel;

}
var myLayers = app.project.activeItem.selectedLayers;
for (var i = 0; i < myLayers.length; i++){
add(myLayers[i]);
}

app.endUndoGroup();



Dan



Return to posts index

Kevin Snyder
Re: Scripting - Add to Essential Graphics Panel
on Apr 1, 2020 at 3:42:25 am

Dan, that works great. Thank you. I appreciate it. I'm trying to wrap my head around what you did to apply it to a version that works on any selected property. It will work with one property selected, but falls apart when I have more than one property selected.

function addSelected(){

var myComp = app.project.activeItem; //Active comp
var selectProps = myComp.selectedLayers[0].selectedProperties; //Selected properties in comp;
var selectProp;
var n;
for (var i = 0; i < selectProps.length; i++){
selectProp = selectProps[i];
if (selectProp.propertyType == PropertyType.PROPERTY){
switch(selectProp.propertyValueType){
case PropertyValueType.OneD:
n = 1;
break;
case PropertyValueType.TwoD:
case PropertyValueType.TwoD_SPATIAL :
n = 2;
break;
case PropertyValueType.ThreeD:
case PropertyValueType.ThreeD_SPATIAL:
n = 3;
break;
case PropertyValueType.COLOR:
n = 4;
break;
default:
n = 0; // just in case
break;
}

}
}
var myLayer = myComp.selectedLayers[0].name; //Get layer name;
var myProp = myComp.selectedLayers[0].selectedProperties[0].name; //Get property name;
var myControl = myProp + " " + "-" + " " + myLayer;//Combine property name and layer name
selectProp.addToMotionGraphicsTemplateAs(myComp, myControl); //Add property to EGP and rename;
app.project.activeItem.motionGraphicsTemplateName = "Master Properties"; //Set template name;
myComp.openInEssentialGraphics(); //Opens comp in essential graphics panel;
}

var selectProp = app.project.activeItem.selectedProperties;
for (var i = 0; i < selectProp.length; i++){
addSelected(selectProp[i]);
}



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]