
Copy link to clipboard
Copied
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 Correct answer
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
...Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Mylenium - Do you know any good scripting guides for createPath I'm trying to learn this as well.

Copy link to clipboard
Copied
@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
Copy link to clipboard
Copied
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.

Copy link to clipboard
Copied
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.name == "Path") {
var prop = selectedProps;
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 = [-sVerts
myIns = [-sOuts
myOuts = [-sIns
}
myShape.vertices = myVerts;
myShape.inTangents = myIns;
myShape.outTangents = myOuts;
myShape.closed = true;
prop.setValue(myShape);
}
}
}
}
Copy link to clipboard
Copied
my mistake sorry! was thinking of expression scripting only

