Skip to main content
Inspiring
October 23, 2020
Answered

Delete strokes with JFSL?

  • October 23, 2020
  • 4 replies
  • 1683 views

Continuing on my JSFL journey...

 

i have a layer that contains strokes and fills. When i loop through the layer's contents, it says there's only one element: a single shape. Fine - so it's treating all the artwork like one shape.

 

i'd like to delete the strokes only, and leave the fills.

If i select everything, and then manually click the strikethrough stroke in the swatch panel, the strokes all disappear. i thought i could do something similar in JSFL, so i tried this (after selecting everything in the layer):

var dom = an.getDocumentDOM();
stroke = dom.getCustomStroke("selection");
stroke.style = "noStroke";
dom.setCustomStroke(stroke);

i've tried it with both "selection" and "toolbar" but neither approach works. 

Is there another/better way to isolate just the strokes on this layer and delete them?  Can i detect them by colour, or some other parameter?

Thanks!

- Ryan

 

    This topic has been closed for replies.
    Correct answer kglad

    good to hear.

     

    post your solution for others.

    4 replies

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    October 24, 2020

    good to hear.

     

    post your solution for others.

    Inspiring
    October 24, 2020

    Ok, but i'm not going to pretend it's elegant. 🙂

    /*
    What i'm trying to do is:
    automatically delete all my green construction lines
    turn the layer back to 100% alpha
    run the "add blue glow" script
    */
    
    var dom = an.getDocumentDOM();
    var tl = dom.getTimeline();
    var layer = tl.layers[ tl.currentLayer ];
    var frame = layer.frames[ tl.currentFrame ];
    
    // Deselect all
    dom.selectNone();
    
    var deletedLine = true;
    
    // Keep double-clicking and deleting strokes
    // until there aren't any strokes left:
    do
    {
    	deletedLine = deleteLines();
    }
    while (deletedLine)
    
    
    function deleteLines()
    {
    	// Search the current frame for a stroke
    	var element;
    	var stroke;
    	var i;
    	var j;
    	var len1;
    	var len2;
    	var edge;
    	var theSelection;
    	var newSelection = [];
    	var vertex;
    
    	// Loop through the elements in the current frame:
    	len1 = frame.elements.length;
    	for( i = 0; i < len1; i++ )
    	{
    		element = frame.elements[ i ];
    
    		var didDeleteLine = false;
    		
    		if(element.elementType == "shape")
    		{
    			// This is a shape!
    			var shape = element;
    
    			// Loop through the edges in the shape:
    			len2 = shape.edges.length;
    			for( j = 0; j < len2; j++ )
    			{
    				edge = shape.edges[j];
    				if(edge)
    				{
    					if(edge.stroke.color != undefined)
    					{
    						// This is a stroke!
    						vertex = edge.getHalfEdge(0).getVertex(0); // Get the stroke's first vertex
    						dom.mouseClick({x:vertex.x, y:vertex.y}, false, false, true); // Double-click it
    						dom.deleteSelection(); Get rid of it
    						j--;
    						didDeleteLine = true; // Flag this because there may be more strokes to delete
    					}
    				}
    			}
    			
    		}
    		return (didDeleteLine);
    	}
    }
    
    // Deselect all
    dom.selectNone();
    kglad
    Community Expert
    Community Expert
    October 24, 2020

    this is how you "would" do it IF you could select an edge:

     

    var el = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0];
    var edgeA = el.edges;

    for(var i=0;i<edgeA.length;i++){
    if(edgeA[i].stroke.color != undefined){
    // select edgeA[i];
    fl.getDocumentDOM().deleteSelection();
    }
    }

    Inspiring
    October 24, 2020

    Thank you, kglad. That's what i was doing, but it kept throwing an error. i tried again on a freshly-drawn layer, and it worked.

     

    However, when the strokes were deleted, it messed up my fill line:

     

    What i wound up doing was drilling down to the stroke edges' vertex level, firing a shift-double-click, and deleting the resulting selection. Kinda goofy, but it did the trick!

    - Ryan

    kglad
    Community Expert
    Community Expert
    October 23, 2020

    then just iterate through the one shape's edges[i].stroke.color property.  if it's not undefined, it's a stroke.

    Inspiring
    October 24, 2020

    i'm having trouble, because it throws an error if i try to reference an edge with a nonexistent edge.

     

    None of these worked:

    an.trace("edge = " + edge); // edge = [object Edge]

    if(edge.stroke)

    if(edge.stroke != undefined)
    if(edge.stroke.color)

    if(edge.stroke.color != undefined)

    Do i have to put it in a try...catch statement, or...?

    Inspiring
    October 24, 2020

    (edge with a nonexistent stroke, i mean)

    kglad
    Community Expert
    Community Expert
    October 23, 2020

    you can use breakApart() after selecting the shape, then check for other elements and for each shape get an array of edges of shapes and then iterate through them checking their stroke property (and even check the stroke properties).

    Inspiring
    October 23, 2020

    The shape is already broken apart. It's a strokeless noodle/snake-shaped drawing created, say, with the brush tool, and there are two random stroke lines overlapping/bisecting it. Because the stroke lines are overlapping the fill blob, the layer is reporting itself as containing a single element of type "shape." It doesn't see two different things (fill and stroke).  i don't want to delete the whole drawing - i just want to remove the strokes. Possible?