ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Draw shape with script

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jeremy Wick
Draw shape with script
on Aug 8, 2018 at 8:06:52 pm

I want to make a script that creates a specific shape layer (the shape of a mouse/cursor). I've figured out how to create a new shape with the proper groups, paths, and fills. But I haven't found a good way to manipulate the actual "Path" properties.

var myComp = app.project.activeItem;
var newCursor = myComp.layers.addShape();
newCursor.property("ADBE Root Vectors Group").addProperty("ADBE Vector Group");
newCursor.property("ADBE Root Vectors Group").property(1).property("ADBE Vectors Group").addProperty("ADBE Vector Shape - Group");
newCursor.property("ADBE Root Vectors Group").property(1).property("ADBE Vectors Group").addProperty("ADBE Vector Shape - Group");
var cpg1f = newCursor.property("ADBE Root Vectors Group").property(1).property("ADBE Vectors Group").addProperty("ADBE Vector Graphic - Fill");
cpg1f.property("ADBE Vector Fill Color").setValue([1,1,1,1]);
newCursor.property("ADBE Root Vectors Group").property(1).property("ADBE Vector Materials Group").remove();
newCursor.property("ADBE Root Vectors Group").addProperty("ADBE Vector Group");
newCursor.property("ADBE Root Vectors Group").property(2).property("ADBE Vectors Group").addProperty("ADBE Vector Shape - Group");
var cpg2f = newCursor.property("ADBE Root Vectors Group").property(2).property("ADBE Vectors Group").addProperty("ADBE Vector Graphic - Fill");
cpg2f.property("ADBE Vector Fill Color").setValue([0,0,0,1]);
newCursor.property("ADBE Root Vectors Group").property(2).property("ADBE Vector Materials Group").remove();


Return to posts index

Dan Ebberts
Re: Draw shape with script
on Aug 8, 2018 at 9:16:13 pm

Add this to the end of your script. It just adds a rounded rectangle, but it'll show you how to build a path:

var myPath = newCursor.property("ADBE Root Vectors Group").property(2).property("ADBE Vectors Group").property("ADBE Vector Shape - Group").property("ADBE Vector Shape");
var myWidth = 300;
var myHeight = 200;
center = newCursor.property("anchorPoint").value; // center mask around anchor point
var myShape = myPath.value;
var vertex0 = [center[0] - myWidth/2, center[1] - myHeight/2];
var vertex1 = [center[0] + myWidth/2, center[1] - myHeight/2];
var vertex2 = [center[0] + myWidth/2, center[1] + myHeight/2];
var vertex3 = [center[0] - myWidth/2, center[1] + myHeight/2];
myShape.vertices = [vertex0, vertex1, vertex2, vertex3];
myShape.inTangents = [[-30,30],[-30,-30],[30,-30],[30,30]];
myShape.outTangents = [[30,-30],[30,30],[-30,30],[-30,-30]];
myShape.closed = true;
myPath.setValue(myShape);



Dan



Return to posts index

Jeremy Wick
Re: Draw shape with script
on Aug 9, 2018 at 7:27:40 pm

Perfect! Thank you, Dan.


Return to posts index


Jeremy Wick
Re: Draw shape with script
on Aug 9, 2018 at 9:02:15 pm

Follow up question: Do you know any methods or plugins for extracting vertices/tangent information from an existing shape? (Either in AE or AI).


Return to posts index

Dan Ebberts
Re: Draw shape with script
on Aug 9, 2018 at 10:52:47 pm

You could try running something like this from the script editor (select your path first):


var myLayer = app.project.activeItem.layer(1);
var myProps = myLayer.selectedProperties;
for (var i = 0; i < myProps.length; i++){
try{
$.writeln("Vertices:" + myProps[i].value.vertices.toSource());
$.writeln("In Tangents:" + myProps[i].value.inTangents.toSource());
$.writeln("Out Tangents:" + myProps[i].value.outTangents.toSource());
}catch(e){
}
}


Dan



Return to posts index

Jeremy Wick
Re: Draw shape with script
on Aug 10, 2018 at 6:11:07 pm

This is great! Thanks again, Dan.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]