Skip to main content
AhmadMurad86
Participant
March 12, 2019
Answered

How can I import a vector to Adobe After Effects only via scripting

  • March 12, 2019
  • 3 replies
  • 4587 views

I'm making an After Effects script that generates simple shapes & animations for kids, and I'm trying to avoid importing vector shapes from Illustrator to After Effects to animate them. And that is working perfectly with the simple shapes such as squares and circles.

Is there any solution for generating complex shapes inside the Extendscript Toolkit, a pure code with no imports or locating some txt file, just by setting the vertices, position and color of the shape and applies it to a new solid as a mask by running the script inside of After Effects?

I'm not talking about images, I need to draw vectors by coding it (same way when you use the pen tool on a solid to draw a mask).

By running the script (File > Scripts > Script Name)

jX6d6.png

You must find this result:

zzYWt.png

This topic has been closed for replies.
Correct answer Theodoros Tziatzios

This is a quite a complex task you are trying to achieve and there is no, one-click solution.

The hard way is to import the source .AI file into After Effects, convert it to a shape layer with "Create Shapes from Vector Layer" and if everything looks ok with the shape layer, copy every vertex coordinates of every shape in every group to your script and have your script rebuild the whole shape structure.

If I were you, I would start by building a small intermediate tool to show me all the vertices of a shape and then copy/embed these vertices inside my script.

Keep in mind that, except for the coordinates of each vertex you will also need the IN and OUT tangent values.

So, if you have a path selected in the timeline (e.g. Shape Layer > Contents > Shape > Path 1 > Path) and run the code below in Extendscript, four prompts will pop-up revealing you all the necessary info to rebuild the selected shape.

var vertex_text = "";

var inTangents_text = "";

var outTangents_text = "";

selectedPath = app.project.activeItem.selectedLayers[0].selectedProperties[0].path.value;

for (var i=0; i < selectedPath.vertices.length; i++) {

    vertex_text = vertex_text + "[" + selectedPath.vertices.toString() + "]";

    inTangents_text = inTangents_text + "[" + selectedPath.inTangents.toString() + "]";

    outTangents_text = outTangents_text + "[" + selectedPath.outTangents.toString() + "]";

    if (i < selectedPath.vertices.length-1) { vertex_text += ","; inTangents_text += ","; outTangents_text += ","; }

} // end for

prompt("The coordinates of the "+i+" vertices of the selected path are: ", vertex_text);

prompt("The inTangents of these vertices are: ", inTangents_text);

prompt("The outTangents of these vertices are: ", outTangents_text);

prompt("The selected path is: ", (selectedPath.closed?"closed":"open"));

You can read about the Shape Object and how to create shapes in Extendscript here: http://docs.aenhancers.com/other/shape/?highlight=tangent

If your shape is quite complex with merged paths etc. (like the reindeer example you mentioned) then you will have to recreate the whole group structure of the shape inside your script. The next step would be to streamline and automate the above process and start building your final script (adding groups, colors, outlines, merging paths).

It is a difficult task, but with a lot of patience it's doable.

3 replies

Rameez_Khan
Legend
April 1, 2019

Hi AhmadMurad86,

Did TheodorosGR's suggestion help at all?

Thanks,

Rameez

AhmadMurad86
Participant
November 20, 2021

yes it did

Theodoros Tziatzios
Theodoros TziatziosCorrect answer
Participating Frequently
March 13, 2019

This is a quite a complex task you are trying to achieve and there is no, one-click solution.

The hard way is to import the source .AI file into After Effects, convert it to a shape layer with "Create Shapes from Vector Layer" and if everything looks ok with the shape layer, copy every vertex coordinates of every shape in every group to your script and have your script rebuild the whole shape structure.

If I were you, I would start by building a small intermediate tool to show me all the vertices of a shape and then copy/embed these vertices inside my script.

Keep in mind that, except for the coordinates of each vertex you will also need the IN and OUT tangent values.

So, if you have a path selected in the timeline (e.g. Shape Layer > Contents > Shape > Path 1 > Path) and run the code below in Extendscript, four prompts will pop-up revealing you all the necessary info to rebuild the selected shape.

var vertex_text = "";

var inTangents_text = "";

var outTangents_text = "";

selectedPath = app.project.activeItem.selectedLayers[0].selectedProperties[0].path.value;

for (var i=0; i < selectedPath.vertices.length; i++) {

    vertex_text = vertex_text + "[" + selectedPath.vertices.toString() + "]";

    inTangents_text = inTangents_text + "[" + selectedPath.inTangents.toString() + "]";

    outTangents_text = outTangents_text + "[" + selectedPath.outTangents.toString() + "]";

    if (i < selectedPath.vertices.length-1) { vertex_text += ","; inTangents_text += ","; outTangents_text += ","; }

} // end for

prompt("The coordinates of the "+i+" vertices of the selected path are: ", vertex_text);

prompt("The inTangents of these vertices are: ", inTangents_text);

prompt("The outTangents of these vertices are: ", outTangents_text);

prompt("The selected path is: ", (selectedPath.closed?"closed":"open"));

You can read about the Shape Object and how to create shapes in Extendscript here: http://docs.aenhancers.com/other/shape/?highlight=tangent

If your shape is quite complex with merged paths etc. (like the reindeer example you mentioned) then you will have to recreate the whole group structure of the shape inside your script. The next step would be to streamline and automate the above process and start building your final script (adding groups, colors, outlines, merging paths).

It is a difficult task, but with a lot of patience it's doable.

Mylenium
Legend
March 12, 2019

Not really. That's just what the AI conversion does and guess why it took 20 years to appear in AE... Such stuff is far from trivial. You could possibly parse text-based formats like plain XML or SVG, which of course is an option to export from AI, but converting binary data in a script is too far fetched.

Mylenium