Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Manipulate shape layer vertices via script

  • Manipulate shape layer vertices via script

    Posted by Charlie Laud on January 13, 2019 at 7:04 pm

    Hi there,

    I’m looking to write a simple script that takes a shape path and randomizes the position of the vertices by a few pixels to create a distorted stroke around the original shape.

    It feels straightforward, but I can’t seem to figure out how to access the path of the vertex information.

    What does the code look like for accessing/manipulating each vertex of a bezier shape path? Can this be done?

    Dan Ebberts replied 7 years, 3 months ago 2 Members · 5 Replies
  • 5 Replies
  • Charlie Laud

    January 13, 2019 at 9:04 pm

    Or better yet –

    Is there a way to create a “custom” shape from an array of points? That way I could copy the values from an existing shape, and create a new shape with slightly modified versions of those values.

  • Dan Ebberts

    January 13, 2019 at 9:29 pm

    Here’s an example that creates a rounded rectangle shape layer:


    var myComp = app.project.activeItem;
    var myShapeLayer = myComp.layers.addShape();
    var myShapeLayerContents = myShapeLayer.property("ADBE Root Vectors Group");
    var myShapeGroup = myShapeLayerContents.addProperty("ADBE Vector Group");
    var myShapeContents = myShapeGroup.property("ADBE Vectors Group");
    var myPathGroup = myShapeContents.addProperty("ADBE Vector Shape - Group");
    var myPath = myPathGroup.property("ADBE Vector Shape");

    var myWidth = 300;
    var myHeight = 200;
    center = myShapeLayer.property("anchorPoint").value;

    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);

    var myFillColor = [.45,.75,.90];
    var myFill = myShapeContents.addProperty("ADBE Vector Graphic - Fill");
    myFill.property("ADBE Vector Fill Color").setValue(myFillColor);

    Dan

  • Charlie Laud

    January 14, 2019 at 3:08 am

    Perfect! Thanks for your help Dan!!

  • Charlie Laud

    January 14, 2019 at 8:40 pm

    Alright, so far so good!

    Now I need to find a way to access the transform properties of the shape itself (not the layer transforms) to copy that data into the new shape as well. (i.e. take the shape Position and Anchor Points and add them to the new shape.)

    What would the code for that be? I’ve been trying to use the documentation to help with this, but it doesn’t seem to provide a clear enough picture of how these hierarchies are structured, so thanks in advance for your help!

  • Dan Ebberts

    January 14, 2019 at 11:41 pm

    Assuming you built it as above, the shape’s Anchor Point, for example, would be:

    myShapeGroup.property(“ADBE Vector Transform Group”).property(“ADBE Vector Anchor”).value;

    You need to get your hands on Jeff Almasol’s wonderful rd_GimmePropPath.jsx script from his site:

    https://www.redefinery.com

    Dan

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