Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions change the X position of null layer incrementally every time user press a left or right button

  • change the X position of null layer incrementally every time user press a left or right button

    Posted by Fabio Apelbaum on April 9, 2015 at 2:36 pm

    HI GUYS, first of all, thank you all you great dedicated people who helps us all with our questions!

    So, I am trying something I never tried before, it might be very simple to do, but just couldn’t find the way to do it on my own….

    I created a comp that holds two pre-comps, one that sets the “day” (Monday through Sunday), the text within this pre-comp is right justified and then a “time” pre-comp that sets the time (12am to 12pm), the text within this pre-comp is right justified.

    Everything works as it should, where I am having problems is that the word “today” and the word “tomorrow” have different lengths and when I replace one for the other, in the main comp it does not look centered. So, as you can see in the UI (picture attached), I created two arrows to move a null object left or right incrementally every time you click on the buttons for either side, the two pre-comps (Day and Time) are parented to this null object.. I dont know how to make the two arrow buttons work…. what script should I write to tell the position of the null object to change by 20 on the x position every time you click that button and so on….. Any ideas? Is this the best way to accomplish this? Is there a better way?

    Thanks again! I am including a screen grab so hopefully you can understand better what I am talking about!

    Take care you all!

    Fabio

    Dan Ebberts replied 11 years, 1 month ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    April 9, 2015 at 5:53 pm

    So the arrow buttons are in a script dialog, is that correct? If so, you just need to set up an onClick handler for each button that reads the current position value of the null, adds/subtracts 10 from the x component and saves the new value.

    Or, you could add an expression to the null that calculates its position by using sourceRectAtTime() to measure the actual size of the text.

    Dan

  • Fabio Apelbaum

    April 9, 2015 at 6:23 pm

    Thank you Dan! Yes, it is on a script I have been creating in ExtendScript. To that specific part this is what I have written so far… Im not really sure how to tell the null to add/substract and save the new value.

    Tried looking in the Scripting guide but couldnt find it. Can you please lead me in the right direction?

    Thank you again!

    Fabio

    var proj = app.project;
    var selectAP = proj.item(7);
    var layerPosition= selectAP.layer('Text_Position');
    var textPosition = layerPosition.property("Position");
    var cbList = new Array();

    //GROUP 2 PANEL

    var groupTwo = myWin.add("panel", undefined, "Please, select the time and day:");
    groupTwo.orientation = "row";

    // ARROWS ON UI
    var leftArrow = groupTwo.add("iconbutton", undefined, "/Applications/Adobe After Effects CC 2014/Scripts/RedSox_Script/Images/left.png","LeftArrow");
    var rightArrow = groupTwo.add("iconbutton", undefined, "/Applications/Adobe After Effects CC 2014/Scripts/RedSox_Script/Images/right.png","RightArrow");

    //LEFT ARROW TO CHANGE DAY/TIME TO CENTER

    leftArrow.onClick = function(){

    layerPosition.property("Transform").property("Position").setValue([0,0,0]);

    };

    //RIGHT ARROW TO CHANGE DAY/TIME TO CENTER

    rightArrow.onClick = function(){

    layerPosition.property("Transform").property("Position").setValue([0,0,0]);

    };

  • Dan Ebberts

    April 9, 2015 at 9:41 pm

    I haven’t test anything, but it should looks something like this:

    var oldVal = layerPosition.property(“Position”).value;
    layerPosition.property(“Position”).setValue([oldVal[0]+10,oldVal[1],oldVal[2]]);

    Dan

  • Fabio Apelbaum

    April 9, 2015 at 10:46 pm

    Wow!!! works like a charm! thank you so much! Dan, let me ask you if you dont mind. I would never guessed to put a 1 for y and a 2 for z. How can I learn more about those details? I couldnt find it in the scripting guide from Adobe.

    Thanks so much for all! owe you big time!

  • Dan Ebberts

    April 9, 2015 at 11:00 pm

    Multidimensional property values are stored in JavaScript arrays. So x,y,z correspond to indexes 0,1,2. For colors, r,g,b,a correspond to indexes 0,1,2,3. There’s a section of Arrays and multidimensional properties in the Expression Basics section of AE Help:

    https://helpx.adobe.com/after-effects/using/expression-basics.html#expression_basics

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy