Thursday, 14 July 2016

How to make something useful in Extendscript pt. 4

The essence of my panel is to store my commonly used expressions. I'm not very good at remembering them, probably because I don't know the Javascript fundamentals very well, so a panel that stores them all would be useful.

After some blundering around I was able to target the first layer in an active comp, and apply a wiggle to the position property.
app.project.activeItem.layer(1).property("Position").expression = "wiggle(2,2)";
What I really wanted though was to target a currently selected property, since I wiggle other things sometimes. There I got stuck, luckily AE guru Dan Ebberts helped me out with this:
props = app.project.activeItem.selectedProperties;
for (var i = 0; i < props.length; i++){
  if (props[i].canSetExpression){
    props[i].expression = "wiggle(2,2)";
This works, thanks again Dan. This whole code now replaces the 'alert' part of our button action
    if  (myList.selection.text=="script01"){
        << alert("pressed something"); >>
The only issue left was in formatting the expressions I wanted to use. In order to accommodate the Javascript characters within the expressions you have to format it using escape characters. This is where the freeFormatter escape character tool comes in handy.

As a follow on I found Fran├žois Tarlier's code on smipple to be very helpful in working out more complex if statements and alerts.


No comments:

Post a Comment