get coordinates of the vertices of a shape layer or a mask

Moderators: Disciple, zlovatt

Post Reply
stefman
Posts: 12
Joined: April 11th, 2009, 8:47 am

Hello,

I'm looking for an expression to find out the coordinates of the vertices of an existing shape layer or a mask.

I know that on his web site* Dan Ebberts presents a script for the creation of a mask on a solid by entering the coordinates of the vertices in the code:

"...
myShape.vertices = [[5,5],[5,45],[45,45],[45,5]]
..."

So, I am wondering if it is possible to find out the position of those vertices once the shape has been created.

For example I would like to end up with a text layer showing those coordinates. But my feeble trial, modifying adobe's classic text layer source expression** didn't work:

"thisComp.layer(index + 1).name + "\rOpacity = " + thisComp.layer(index + 1).?maskPath?.value"


Does someone know if it is possible to determine and to show the position of those vertices?

Thank you very much in advance for your reply.


Cheers,

Stefan


P.S.

sources:

* : http://www.motionscript.com/ae-scriptin ... ted-1.html
by Dan Ebberts

** : the original expression is: "thisComp.layer(index + 1).name + "\rOpacity = " + thisComp.layer(index + 1).opacity.value"
and can be found at: http://help.adobe.com/en_US/AfterEffect ... 7a26a.html
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

Hi Stefan,
Check out nab's script "MaskVertexExpression" here:
http://www.nabscripts.com/downloads_en.html
(script number 16)
That script changes the position of mask's vertices (watch the demo file).

Koby.
stefman
Posts: 12
Joined: April 11th, 2009, 8:47 am

Thank you very much for the link Koby,

but unfortunately the script does not exactly what I am looking for.

Actually, I would like to find a way to get the x and y coordinates of each single vertex.
So, for example, if I created a trianglular mask I would like to be able to see the x and y coordinates of every one of those three vertexes.

positions of the vertexes of my triangular mask:

position of vertex 1: [value of X, value of Y]

position of vertex 2: [value of X, value of Y]

position of vertex 3: [value of X, value of Y]


I know that this might not be a really commun question.


Thank you in advance for any reply.


Stefan
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

Hi Stefan,
I didn't mean you take the script as is, I meant that you see the way he takes the values from the vertices...
see on line 160, it should be something like:

Code: Select all

var comp = app.project.activeItem;
var mask = comp.selectedProperties[0];
var maskShape = mask.maskShape;
var shape = maskShape.numKeys ? maskShape.valueAtTime(comp.time,false) : maskShape.value;
var verts = shape.vertices;
alert(verts[0]);
This code will write the first vertex location as an alert message.
(make sure you select one mask before you operate this script code)

Koby.
stefman
Posts: 12
Joined: April 11th, 2009, 8:47 am

Hi Koby,

wow, that works fine!
Sorry, at the first time I hadn't understood what you wanted me to do.

Thank you very much!

I get the the alert message with the position of the first vertex.

Now, I'am trying to transform the script to an expression which I could apply to the source of a text layer. This way, I could have a text layer showing the vertex position. But I am already getting aware of that I won't be able to do this. (I even don't manage to show the x and y coordinates of a normal position of a normal layer.
By using
"thisComp.layer(index + 1).name + "\rPosition = " + thisComp.layer(index + 1).transform.position[0]"
I only get a very bizzar value that has nothing to do with any x or y coordinate.)

But, is it worth trying to find the expression or is it techniqually just impossible?

And the second question is if there is a possiblity to show the positions of the other vertexes of the shape at the same time. Even if it was with an alert message.

Bye,

Stefan
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

Hi Stefan,
I don't know how to access mask vertices via expression... I don't think it is possible...
As for writing the position of a layer in a text layer, there shouldn't be any problem using the expression you wrote...
just make sure you apply it to the "Source Text" property of the text layer...
And lastly, as for getting the rest of the vertices positions via the alert message in a script, just write the next index numbers: (at the end of the script code I wrote in the last post)

Code: Select all

alert(verts[0]);
alert(verts[1]);
alert(verts[2]);
...
note you have the number of vertices of the mask in:

Code: Select all

verts.length
Koby.
Mylenium
Posts: 139
Joined: July 20th, 2005, 12:07 am

stefman wrote: Now, I'am trying to transform the script to an expression which I could apply to the source of a text layer.
Expressions cannot access mask data. Use the script, dump the result to a text file, copy&paste to your text layer.

Mylenium
[Pour Mylène, ange sur terre]
stefman
Posts: 12
Joined: April 11th, 2009, 8:47 am

OK, merci.

It's also good to know when something is simply impossible and that it's no use to keep on trying. (I am talking about the expression option.)

Thanks a lot to you all.

Stefan
Post Reply