Page 1 of 1

Add a Slider and an Expression to the selected Properties?

Posted: October 15th, 2013, 10:41 am
by zioteo
I'm having some problems with my code, I setted up the GUI. Now I'm trying to add an expression to the selected properties of a layer an also 2 Slider Control. The button works because I did some tests but the function doesn't work :(

Code: Select all

myPanel.grp.myTabbedPanel.myTab2.wiggleButton.onClick = function wiggleExpression (){
            app.beginUndoGroup("Wiggle");
            var myExpr = "wiggle(effect(\"Wiggle Frequency\")(\"ADBE Slider Control-0001\"),effect(\"Wiggle Amplitude\")(\"ADBE Slider Control-0001\"));";
            var addSlider1 = app.project.activeItem.selectedLayers.Effects.addProperty("ADBE Slider Control");
            addSlider1.name = "Wiggle Frequency";
            var addSlider2 = app.project.activeItem.selectedLayers.Effects.addProperty("ADBE Slider Control");
            addSlider2.name = "Wiggle Amplitude";
            app.project.activeItem.selectedLayers.selectedProperties.expression = myExpr;    
            app.endUndoGroup();
        }
I don't know how to check if a property is selected so you can say me it...

Re: Add a Slider and an Expression to the selected Propertie

Posted: October 15th, 2013, 2:47 pm
by Paul Tuersley

Code: Select all

var activeItem = app.project.activeItem;
if (activeItem != null && activeItem instanceof CompItem) {
	if (activeItem.selectedLayers.length != 1 || activeItem.selectedProperties.length != 1) {
		alert("You need to select one property first.");
	} else {
		var theProp = activeItem.selectedProperties[0];	// need to store the selected property before adding the effects as that will change the selection
		app.beginUndoGroup("Wiggle");
		var myExpr = "wiggle(effect(\"Wiggle Frequency\")(\"ADBE Slider Control-0001\"),effect(\"Wiggle Amplitude\")(\"ADBE Slider Control-0001\"));";
		var addSlider1 = app.project.activeItem.selectedLayers[0].Effects.addProperty("ADBE Slider Control");
		addSlider1.name = "Wiggle Frequency";
		var addSlider2 = app.project.activeItem.selectedLayers[0].Effects.addProperty("ADBE Slider Control");
		addSlider2.name = "Wiggle Amplitude";
		theProp.expression = myExpr;    
		app.endUndoGroup();

	}
}

Re: Add a Slider and an Expression to the selected Propertie

Posted: August 27th, 2014, 2:38 am
by Matthieu Robert
It seems to work with transformation properties, like position or rotation, but not for any effect's parameter.

Is there a way to script something that would say "add this expression to the selected effect's param" ?

Re: Add a Slider and an Expression to the selected Propertie

Posted: August 31st, 2014, 5:22 pm
by axymark
In Paul's example theProp gets object property, while for the effect parameters you need to grab property group and than a property under that group.

Code: Select all

var comp = app.project.activeItem;
var prop = app.project.activeItem.selectedProperties[0];
var expr = "x = 50;";

if (prop.isEffect == true) {
    for (var i = 1; i <= prop.numProperties; i++) {
        if (prop.property(i).selected == true) {
            prop.property(i).expression = expr;
        }
    }
} else {
    prop.expression = expr;
}
Not sure if you can directly get the selected property under the Effects group... I looped through as a quick work around...

Re: Add a Slider and an Expression to the selected Propertie

Posted: September 1st, 2014, 12:20 pm
by Matthieu Robert
It works perfectly, thank you very much.