Changing stroke scale modes with a JSFL script?

569 views Asked by At

I know there aren't many who use JSFL, but I thought it was worth a shot:

Is there any way I am able to use JSFL to loop through the strokes in a document and change their scale type to a different setting? I know how to do it in the Flash IDE (within the properties panel while drawing) and the JSFL Documentation does hint at the ability to change the scaleType on page 481, but I fear this may only be doable when creating new strokes within the script (not editing strokes that are already present within the document.

The definitive answer to this question essentially lies in whether you can retrieve existing stroke objects within a document via JSFL.

2

There are 2 answers

0
Ray_Poly On

here is an approach that I have been working with, although it's got a few bugs I think, be careful.

for (j=0; j < selection.edges.length; j++)
    {
        var cubicPoints = selection.getCubicSegmentPoints(j);
//      for (var i=0; i<cubicPoints.length; i++) {
//          trace("index " + i +" x: " + cubicPoints[i].x  + " y: " + cubicPoints[i].y);
//      }
        if ( Math.abs(cubicPoints[0].x - cubicPoints[3].x) && Math.abs(cubicPoints[0].y - cubicPoints[3].y))
        {
            border_object.radius_array.push(Math.abs(cubicPoints[0].x - cubicPoints[3].x));
            continue;
        }
        //it's not a corner so get the stroke properties
        var obj     = {};
        obj.x_pos   = cubicPoints[0].x;
        obj.y_pos   = cubicPoints[0].y;

        if (selection.edges[j].stroke)
        {
            obj.stroke_thickness = selection.edges[j].stroke.thickness == undefined ? '0' : selection.edges[j].stroke.thickness;

            if (selection.edges[j].stroke.shapeFill)
                obj.fill_properties = getFillProperties(selection.edges[j].stroke);
            else
                obj.fill_properties = [];
        }

        border_object.stroke_properties.push(obj);
    }

I bet you can find a way to change the stroke objects at your will.

0
Daniel On

This will iterate over all symbols in the library and change the stroke width. Just change stroke_width to the desired width before running it.

var stroke_width = 20;

fl.trace("Changing all strokes width to "  + stroke_width);

function changeStroke(element, width)
{
    if (element.elementType == "shape") {
        var stroke = element.getCustomStroke();
        stroke.thickness = width;
        element.setCustomStroke(stroke);

        // recurse for groups
        for (var iSubE in element.members) {
            var sub_element = element.members[iSubE];
            changeStroke(sub_element, width);
        }
    }
}

var libItems = fl.getDocumentDOM().library.items;
for (var item_it in libItems)
{
    var item = libItems[item_it];
    if (item == undefined || item.symbolType == undefined)
    {
        continue;
    }

    var timeline = item.timeline;
    for (var layer_it in timeline.layers)
    {
        var layer = timeline.layers[layer_it];
        var frame = layer.frames[0];
        for (var element_it in frame.elements)
        {
            var element = frame.elements[element_it];
            changeStroke(element, stroke_width);
        }
    }
}