0

I am trying to write a JSFL command that works with the currently selected vertex/verticies point/points, I can't find any method to access the currently selected point or points..

I have searched through the JSFL Reference and the only method that deals with selected vertices is moveSelectedBezierPointsBy();

vidhill
  • 13
  • 1
  • 4

2 Answers2

2

Trying to solve similar problem i make some dirty trick, that can be helpful:

// array for some manipulations
var selPoints = new Object();

// array with all points in layer[0] and frames[0] 
var allBezierPoints = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].vertices

// read and write all points coord
for ( i in allBezierPoints ) {
    selPoints[i] = { x:allBezierPoints[i].x, y:allBezierPoints[i].y }   
}

// now dirty trick - move selected points by 1 px on X
fl.getDocumentDOM().moveSelectedBezierPointsBy({x:1, y:0});

// reseting all points
allBezierPoints = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].vertices

// compare old coord and new coord of all points
for ( i in allBezierPoints ) {
    // if coords similar, ther erase this point from array
    if ( allBezierPoints[i].x == selPoints[i].x ) delete selPoints[i];
}

// move selected points back
fl.getDocumentDOM().moveSelectedBezierPointsBy({x:-1, y:0});

// now we have array with selected points and they coordinates
for ( i in selPoints) {
    fl.trace ( "Point " + i + " X: "+selPoints[i].x +", Y: "+ selPoints[i].y)
}
  • Massively delayed reply, but yes, it does seem that this is the only way to do what I wanted. Thanks – vidhill Mar 25 '14 at 15:14
0

It really depends what you are trying to do with the vertices, but this should get you started.

Here is some code I've used in the past to retrieve vertex info from shapes on the stage:

// Trace Vertex Information - Andrew Doll
// http://www.andrewdollanimation.com/

// Clear the output panel.
fl.outputPanel.clear();

var dom = fl.getDocumentDOM();
var tl = dom.getTimeline();
var foundMovieClips = false;
var layer;
var frame;
var element;
var vertices = [];
var movieClips = [];
var newLine = "\r\n";
var lockStatus;

// grab layers
var layers = tl.layers;

// layer loop
for (var i = 0; i < layers.length; i++)
{
    layer = layers[i];

    // Check if the layer is locked.
    lockStatus = layer.locked;
    if (lockStatus)
    {
        layer.locked = false;
    }
    // Frame loop 
    for (var j = 0; j < layer.frames.length; j++)
    {
        frame = layer.frames[j];

        // Element loop
        for (var k = 0; k < frame.elements.length; k++)
        {
            element = frame.elements[k];
            element.selected = true;

            // Only check elements that are shapes.
            if (element.elementType == 'shape')
            {
                vertices = element.vertices;
                var vertArray = [];

                // Vertice loop
                for (var l = 0; l < vertices.length; l++)
                {
                    // Push the x and y coordinates of the vertices to the vertArray.
                    vertArray.push(' x: ' + vertices[l].x + ' y: ' + vertices[l].y);
                }

                // Trace the vertex count per frame.
                fl.trace('The vertex count of frame ' + (j + 1) + ' on ' + layer.name + ' is: ' + vertices.length + newLine);

                for (var m = 0; m < vertArray.length; m++)
                {
                    // Trace the vertex locations.
                    fl.trace('Vertex ' + (m + 1) + ' on frame ' + (j + 1) + ' is located at: ' + vertArray[m]);
                }
            }
            else if (element.elementType == 'instance')
            {
                // If a movie clip is found add it to the movie clips array.
                foundMovieClips = true;
                movieClips.push(element.libraryItem.name);
            }
        }
        if (foundMovieClips)
        {
            foundMovieClips = false;
            fl.trace('LAYER:  ' + layer.name + ' FRAME:  ' + (j + 1) + ' SYMBOL:  ' + movieClips[j]);
        }
    }
}

The code above will run through the frames on all layers of the main timeline and trace out the vertex count of each frame, and if it encounters a movieclip instead of a shape it will trace out the name of the movie clip. As well as tracing out the vertex count it will also trace out the X and Y coordinate of each vertex on the shape elements if finds on each frame.

Going further you could use the JSFL method: vertex.setLocation() to run through the array of vertex objects and move them around to a new X and Y if that is what you are wishing to do. Again, it really depends on what you are trying to do with the vertices in the end, but this should get you started. Hope you find this answer helpful.

andrewdoll
  • 146
  • 5
  • Thanks for the reply, that solution is helpful but doesn't solve my issue. To clarify I will explain what I am trying to do... For example, I have a shape that contains 8 vertices, if I am in the 'Subselection Tool' and I have two of the vertices selected, I want to run my command and get the x and y distance between the two vertices – vidhill May 07 '13 at 10:15