ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Manipulate shape layer vertices via script

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Charlie Laud
Manipulate shape layer vertices via script
on Jan 13, 2019 at 7:04:48 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?


Return to posts index

Charlie Laud
Re: Manipulate shape layer vertices via script
on Jan 13, 2019 at 9:04:36 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.


Return to posts index

Dan Ebberts
Re: Manipulate shape layer vertices via script
on Jan 13, 2019 at 9:29:54 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



Return to posts index


Charlie Laud
Re: Manipulate shape layer vertices via script
on Jan 14, 2019 at 3:08:55 am

Perfect! Thanks for your help Dan!!


Return to posts index

Charlie Laud
Re: Manipulate shape layer vertices via script
on Jan 14, 2019 at 8:40:53 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!


Return to posts index

Dan Ebberts
Re: Manipulate shape layer vertices via script
on Jan 14, 2019 at 11:41:20 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:

http://www.redefinery.com


Dan



Return to posts index

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