Smipple is shutting down Nov 30, 2017. Some features are currently disabled.
Profile image for fr tr francoisgfx
this snippet will set an expression to the selected properties
Language
JavaScript
Tags
ae aescripts aftereffects afterfx expression ft-Toolbar fttoolbar js jsx toolbar
Favorited By
Profile image for takuya hosogane

Set Expression to selected property (in AE)

1 /********************************************************* 2 SET EXPRESSION TO SELECTED PROPERTY 3 snippet for After Effects 4 made for ft-Toolbar http://aescripts.com/ft-toolbar/ 5 http://www.francois-tarlier.com 6 *********************************************************/ 7 8 // this snippet will set an expression to the selected properties 9 10 // add this code to a JAVASCRIPT button in ft-toolbar 11 12 13 // write the expression you need into Quotes here. 14 var ft_Tb_Expression = 'wiggle(10,30);' 15 16 17 18 19 var ftTb_MyComp = app.project.activeItem; // our current selected & opened comp 20 if(ftTb_MyComp && ftTb_MyComp.selectedLayers[0].selectedProperties[0]){ // if a comp and at least one property is selected 21 for(var i = 0 ; i < ftTb_MyComp.selectedLayers.length; i++){ // go trough each selected layers 22 var ftTb_currentLayer = ftTb_MyComp.selectedLayers[i]; 23 for(var j = 0 ; j < ftTb_currentLayer.selectedProperties.length; j++){ // go through each selected properties 24 var ftTb_currentProperty = ftTb_currentLayer.selectedProperties[j]; 25 if(ftTb_currentProperty.canSetExpression) { 26 ftTb_currentProperty.expression = ft_Tb_Expression; 27 }else{ 28 alert("Can't add expression to the selected property"); 29 }; 30 }; 31 }; 32 }else{ 33 alert("properties of an effect or a layer has to be selected"); 34 };

Comments

Profile image for Vũ Hari HariVu 2017-04-11

Thank you about your code
But have one thing that I have been additional, as following

var ft_Tb_Expression = 'wiggle(10,30);'

var ftTb_MyComp = app.project.activeItem; // our current selected & opened comp
var ftTb_currentLayer = ftTb_MyComp.selectedLayers[i];
if (ftTb_currentLayer == null){
alert("Please select layer first!");
return;
}

if(ftTb_MyComp && ftTb_MyComp.selectedLayers[0].selectedProperties[0]){ // if a comp and at least one property is selected
for(var i = 0 ; i < ftTb_MyComp.selectedLayers.length; i++){ // go trough each selected layers

for(var j = 0 ; j < ftTb_currentLayer.selectedProperties.length; j++){ // go through each selected properties
var ftTb_currentProperty = ftTb_currentLayer.selectedProperties[j];
if(ftTb_currentProperty.canSetExpression) {
ftTb_currentProperty.expression = ft_Tb_Expression;
}else{
alert("Can't add expression to the selected property");
return;
};
};
};
}else{
alert("properties of an effect or a layer has to be selected");
return;
};