Add a Slider and an Expression to the selected Properties?

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
zioteo
Posts: 2
Joined: September 10th, 2013, 8:41 am

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...
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

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

	}
}
Matthieu Robert
Posts: 2
Joined: August 26th, 2014, 3:25 am

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" ?
User avatar
axymark
Posts: 23
Joined: November 29th, 2013, 7:04 am

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...
Matthieu Robert
Posts: 2
Joined: August 26th, 2014, 3:25 am

It works perfectly, thank you very much.
Post Reply