ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to set vertices as expression in script?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Pawel Zelwan
How to set vertices as expression in script?
on Jun 20, 2020 at 6:43:10 am

Hello

I would like to set the vertex path value in the script as an expression.
I know this is possible with other values,
so I tried it in an analogous way, but to no avail.

I don't know JavaScript well, so maybe I am making a school mistake.

It is important for me not to duplicate quite large cartographic data tables,
but to use references to them in separate layers of the composition.

I attach a sample script.

I would like a hint.

Pawel

myShape.vertices.expression = "thisComp.layer("country shape").content("Country").content("Feature 1").content("Path 1").path";


Return to posts index

Filip Vandueren
Re: How to set vertices as expression in script?
on Jun 21, 2020 at 9:40:01 am

Hi Pawel,

A slight mixup:

expressions can be set on properties of your layers that can be keyframed, for example the shape of a path.
Vertices however, are used inside of your scripting code to access the values of individual points inside of a path or mask.

In other words there is no property "vertices" in your layer or timeline, that's why you can't assign it an expression. Just as you can query the name of a layer, but you can't assign it an expression.

In your case, it looks like you don't need to manipulate any vertices, but simply copy the shape from somewhere else.
This means you should simply set an expression on the path that points to the path you need.
something like below.

Feature.property("Contents").property(1).property("ADBE Vector Shape").expression = "thisComp.layer("Shape Layer 1").content("Shape 1").content("Path 1").path;"




Return to posts index

Pawel Zelwan
Re: How to set vertices as expression in script?
on Jun 21, 2020 at 11:11:31 am

You explained it very well to me, Filip. Thank you.

I suspected some school confusion.
I understand that I was simply referring to a non-existent value in the script.

I saved all the paths on a separate data layer
and created references that match the pattern you provided.

It worked!

Tell me, Filip, if there is any way
to refer to such tables saved in an external library?

Let's say:
Feature.property("Contents").property(1).property("ADBE Vector Shape").expression = "footage(\"lib.jsx\").sourceData['country']['shape']";

... and lib.jsx content:
{
'country':{'shape':[[555.42,978.48],[558.96,974.58]...,[563.81,963.52]],
}


I could not construct the correct syntax.

Of course, it is about the possibility of easy use of arrays in other projects.


Return to posts index


Pawel Zelwan
Re: How to set vertices as expression in script?
on Jun 21, 2020 at 11:15:44 am

Of course, the sample library code does not have the necessary right curly brace.


Return to posts index

Filip Vandueren
Re: How to set vertices as expression in script?
on Jun 21, 2020 at 11:17:12 am

Yes, there is the possibility to import an external JSON or csv file as "footage" in your project. This is called a "datasource" and then you can reference that with expressions.

The userguide offers a good starting point I hope:

https://helpx.adobe.com/be_nl/after-effects/using/data-driven-animations.ht...



Return to posts index

Pawel Zelwan
Re: How to set vertices as expression in script?
on Jun 21, 2020 at 11:25:08 am

I'll look at this carefully. Thanks for your help.


Return to posts index


Filip Vandueren
Re: How to set vertices as expression in script?
on Jun 21, 2020 at 11:45:26 am

to get you started:

say I have file "shapes.JSON" like this:

{
"triangle":{
"p": [[-222,-200],[-428,70],[-40,112]],
"i": [[0,0],[0,0],[0,0]],
"o": [[0,0],[0,0],[0,0]],
"c": true
},
"star":{
"p": [[-296,-252],[-318,-54],[-564,-54],[-332,10],[-430,254],[-279.625,30.75],[-43.4375,205.0625],[-242,-8],[-32,-94],[-254,-62]],
"i": [[0,0],[30,-24],[0,0],[-16,-34],[0,0],[-30.375,1.25],[0,0],[-8,30],[0,0],[24,20]],
"o": [[0,0],[-30,24],[0,0],[16,34],[0,0],[30.375,-1.25],[0,0],[8,-30],[0,0],[-24,-20]],
"c": true
}
}
(p, i, o and c are shorthand for points, inTangents, outTangents and closed)

I import that JSON file in my project.

I create a shapelayer, and give the Path this expression:
shapeName=thisLayer.name;

j=footage("shapes.json").sourceData;
s=j[shapeName];

createPath(s.p, s.i, s.o, s.c); // points, inTangents, outTangents, isClosed


Now if I rename my shape-layer to "star" it will be a star, if I rename if to "triangle", it will be a triangle.

of course you can use different ways of setting/looking up the needed shape, doesn't have to be via layername.

Good luck !



Return to posts index

Pawel Zelwan
Re: How to set vertices as expression in script?
on Jun 21, 2020 at 11:50:23 am

Thank you for your kindness, Chris.

I will follow your valuable lessons.

Pawel


Return to posts index

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