6 Replies Latest reply on Jan 7, 2018 4:32 PM by sillybomb

    Is there a way to createPath() from script

    Clay McAvoy Level 1

      I love the new createPath() method in CC 2018.  However, I'm not seeing a mechanism to modify or create paths from a script.  Am I missing it?

       

      thanks,

      Clay

        • 1. Re: Is there a way to createPath() from script
          Mylenium Most Valuable Participant

          Scripts use a different syntax and distinguish between masks, shape layers and motion paths. thoise functions have been there for eons. I suggest you actually study the scripting guide or freely avialable script examples.

           

          Mylenium

          • 2. Re: Is there a way to createPath() from script
            sillybomb Level 1

            Mylenium - Do you know any good scripting guides for createPath I'm trying to learn this as well.

            • 3. Re: Is there a way to createPath() from script
              Clay McAvoy Level 1

              @sillybomb

              I was expecting an actual createPath() function or something similar, but it doesn't exist in scripting.  The way to do this with scripts is the same as any other property in regards to reading and setting it (using property.value, property.setValue, property.valueAtTime(time, evaluate), etc.).  However, you need to set a path value using a shape object.  So, you create and manipulate a shape in your script (or "get" it from an existing path property) and then set the target path property to that shape object.

               

              for example:

              -------

              var myShape = new Shape();

                  

              myShape.vertices = [[0, 100], [100, 100], [100, -100], [0, -100]];

              myShape.inTangents = [[0, 0], [0, 0], [0, 0], [0, 0]];

              myShape.outTangents = [[0, 0], [0, 0], [0, 0], [0, 0]];

              myShape.closed = true;

               

              myPathProperty.setValue(myShape);

              -------

               

              There is a section for "shape object" in this handy scripting guide...

              Welcome to the After Effects Scripting Guide! — After Effects Scripting Guide 0.0.1 documentation

               

              Hope that helps,

              Clay McAvoy

              • 4. Re: Is there a way to createPath() from script
                sillybomb Level 1

                Hi Clay

                 

                I was playing around with it a bit last night

                 

                I think you might be able to get what you want by creating the arrays like you have

                 

                a = [[0, 100], [100, 100], [100, -100], [0, -100]];

                createPath(a,inTangents = [], outTangents = [], is_closed = true);

                 

                then you can create the array points any way you like, using for loop or any method of math-magic.

                • 5. Re: Is there a way to createPath() from script
                  Clay McAvoy Level 1

                  Yes, I'm pretty well traveled on using createPath() in expressions since it came out in October, but createPath() doesn't exist in scripting (extendScript).  The original question was to utilize the same behavior in a script, which I've figured out since, using the shape object.  For example, here's one I use to flip a path horizontally (while keeping the vertices in the same relative position so the shape doesn't flip when animated but instead morphs into the reversed shape, if that makes sense). There may be more direct ways to code it but it works.

                   

                  function flipPath() {

                   

                      if (activeItem != null && activeItem instanceof CompItem) {

                          var selectedProps = activeItem.selectedProperties;

                   

                          for (i = 0; i < selectedProps.length; i++) {

                              if (selectedProps[i].name == "Path") {

                                  var prop = selectedProps[i];

                                  var p = prop.value;

                                  var myShape = new Shape();

                   

                                  sVerts = p.vertices;

                                  sIns = p.inTangents;

                                  sOuts = p.outTangents;

                                  numVerts = myVerts.length;

                                  lastVert = numVerts - 1;

                                   

                                  for (i = 0; i <= lastVert; i++) {

                                      r = lastVert + 1 - i;

                                      if (i == 0) r = 0;

                    

                                      myVerts[i] = [-sVerts[r][0], sVerts[r][1]];

                                      myIns[i] = [-sOuts[r][0], sOuts[r][1]];

                                      myOuts[i] = [-sIns[r][0], sIns[r][1]];

                                  }

                                 

                                  myShape.vertices = myVerts;

                                  myShape.inTangents = myIns;

                                  myShape.outTangents = myOuts;

                                  myShape.closed = true;

                                  prop.setValue(myShape);

                              }

                          }

                      }

                  }

                  • 6. Re: Is there a way to createPath() from script
                    sillybomb Level 1

                    my mistake sorry! was thinking of expression scripting only