[JSFL] Moving Shape Points

Participant ,
Dec 12, 2020 Dec 12, 2020

Copy link to clipboard

Copied

Hello, I am seeking a way to move shape points with JSFL.

 

I am somewhat new to JSFL and I'm confused about the different types of points. In the API documentation, I have seen these point methods: document.moveSelectedBezierPointsBy(), getCubicSegmentPoints, and vertex.setLocation(). I don't understand which I should use to move.

 

Here is an example of a shape I'd like to modify. It has three Bezier points.

Screen Shot 2020-12-12 at 11.13.58 AM.png

If I use document.moveSelectedBezierPointsBy() it works as expected, however, for my script I need to be able to automate this for each layer and frame, so I would need to use JSFL to select Bezier Points, and I have not found a method in the API for doing this. 

 

As I can select an element with element.selected, I thought I could change the shape using the vertices of the selected element. With this code, it returns an array of 12 vertices, which is different than the length of the Bezier points (3).

var verts = an.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].vertices
an.trace(verts.length); // 12

 

This is also the same length when getting the length of the shape's edges which is unexpected (I'd expect 2 vertices / 1 edge). If I try and move those 12 vertices, it will not move the Bezier handles of the vertices.

var shape = an.getDocumentDOM().selection[0]; 
shape.beginEdit();
for (i=0; i<shape.edges.length; i++)
{
    var hEdge = shape.edges[i].getHalfEdge(0); 
    var vertex = hEdge.getVertex();
    x = vertex.x-20;
    y = vertex.y-20;
    vertex.setLocation(x, y);
}
shape.endEdit();

Result:

Screen Shot 2020-12-12 at 11.25.01 AM.png

My questions are:

  1. Is there a way to select Bezier points through JSFL so I can use document.moveSelectedBezierPointsBy()?
  2. If not, how can I move the vertices' Bezier handles together with the Bezier points using the shapes' vertices?

 

Thank you.

 

 

TOPICS
Code , How to

Views

95

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

LATEST

Hey blastframe!
I have exactly the same problem. 

There doesn't seem to be a way to manipulate the bezier handles without selecting them manually. 

I nearly got it to work with Vertices. But if there are curves involved.... it makes lot of angry spaghetti!!

Did you find a solution?

I'm going to continue experimenting with possibly logging the x,y coords of the vertexes and then drawing a new line that's slightly different. .... but I'm not confident! 8)😂

 

Randomly Wiggle Beziers v0011.gif

Randomly Wiggle Beziers v0010.gif

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines