Skip to main content
liors51023776
Participant
December 19, 2016
Question

creating shape from text and get the path

  • December 19, 2016
  • 2 replies
  • 1208 views

Hi everyone!

I am trying to get an answer for this question.

I am working with ExtendScript, and with After Effect.

I have a script like this one:

var comp = app.project.items.addComp('test', 1920, 1080, 1, 30, 25);

var layer = comp.layers.addText('C');

What I am trying to do is to create shape from text by code in extendscript and then to get the path of the shape to array

that will contain the points of the path also in code.

I am sorry but i am beginner.

is there an easy way to do that?

This topic has been closed for replies.

2 replies

UQg
Legend
December 20, 2016

Hi,

you can execute the code below and follow step by step in estk to see what it does.

(past the execute command it does nothing except accessing properties in the created shape layer)

var comp = app.project.items.addComp('test', 1920, 1080, 1, 30, 25);

var textLayer = comp.layers.addText('Test');

// There is no scripting method to create shapes from text ==> use a menu commend

comp.openInViewer();

app.project.executeCommand(app.findMenuCommandId("Creates Shapes from Text"));

// At this stage, the comp is open in a viewer, the text layer is disabled, and the newly created shape layer is first in stack.

var shapeLayer = comp.layer(1);

var i, I, group, character;

var j, J, pathGroup, pathProperty, shape, vertices, inTangents, outTangents, closed;

I = shapeLayer.content.numProperties;

for (i=0; i<I; i++){

    group = shapeLayer.content.property(i);

    character = group.name;

  

    // Path groups come first.

    // There can be one or more, depending on the font character (eg 1 for E, 2 for e)

  

    j=1; J = group.content.numProperties;

    while (j<=J && group.content.property(j).matchName==="ADBE Vector Shape - Group"){

        pathGroup = group.content.property(j);

        pathProperty = pathGroup.path;    // or : pathGroup.property("ADBE Vector Shape")

        shape = pathProperty.value;

      

        // shape is a Shape object as described in the After Effects Scripting Guide.

        // Its control points are splitted in three arrays :

        //    vertices: Array of 2D points

        //    inTangents : Array of 2D vectors (shape.inTangents : the incoming tangent at vertex n)

        //    outTangents : Array of 2D vectors (shape.outTangents : the outcoming tangent at vertex n)

        // (points and vectors are both represented by arrays of the form [x,y])

      

        vertices = shape.vertices;

        inTangents = shape.inTangents;

        outTangents = shape.outTangents;

        closed = shape.closed;    // should be true for a component of a font character

      

        /*

        * do stuff with that shape

        */

      

        j++;

        };

    };

Xavier

UQg
Legend
December 20, 2016

Edit : just realized that the character represented by the group is not the group name, but more something like this:

var temp = group.name.split(" ");

var character = temp[0];

var occurrence = temp.length>1 ? parseInt(temp[1], 10) : 1;

Xavier

Alex White
Legend
December 20, 2016

This code will find all vertices and collect them into array.

var comp = app.project.items.addComp('test', 1920, 1080, 1, 30, 25);

var layer = comp.layers.addText("C");

comp.openInViewer();    // open comp

app.executeCommand(3781);   // convert text to shape

var shapeGroup = comp.selectedLayers[0]("ADBE Root Vectors Group")(1);

var verts = []; // array with points of the paths

/* FIND ALL SHAPE PATHS */

for(var i = 1; i <= shapeGroup.numProperties; i++){

    if(shapeGroup("ADBE Vectors Group")(i).name == shapeGroup.name){

       

        verts.push(shapeGroup("ADBE Vectors Group")(i)("ADBE Vector Shape").value.vertices); 

    }

}

alert(verts);