Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Draw shape with script

  • Draw shape with script

    Posted by Jeremy Wick on August 8, 2018 at 8:06 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();

    Jeremy Wick replied 7 years, 11 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    August 8, 2018 at 9:16 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

  • Jeremy Wick

    August 9, 2018 at 7:27 pm

    Perfect! Thank you, Dan.

  • Jeremy Wick

    August 9, 2018 at 9:02 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).

  • Dan Ebberts

    August 9, 2018 at 10:52 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

  • Jeremy Wick

    August 10, 2018 at 6:11 pm

    This is great! Thanks again, Dan.

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