• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Delete strokes with JFSL?

Participant ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

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

 

Views

728

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

correct answers 1 Correct answer

Community Expert , Oct 24, 2020 Oct 24, 2020

good to hear.

 

post your solution for others.

Votes

Translate

Translate
Community Expert ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

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).

Votes

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
Participant ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

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?

Votes

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 Expert ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

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

Votes

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
Participant ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

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...?

Votes

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
Participant ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

(edge with a nonexistent stroke, i mean)

Votes

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
Participant ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

blob.jpg


This is the "artwork" i'm testing on btw. (i didn't realize i could paste pictures here.) The blue squiggle is a fill, and the two black lines are both strokes. The whole thing reports as a single shape element. i'm trying to select and delete the black strokes.

Votes

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 Expert ,
Oct 24, 2020 Oct 24, 2020

Copy link to clipboard

Copied

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();
}
}

Votes

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
Participant ,
Oct 24, 2020 Oct 24, 2020

Copy link to clipboard

Copied

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:

blob1.jpgblob2.jpg

 

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

Votes

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 Expert ,
Oct 24, 2020 Oct 24, 2020

Copy link to clipboard

Copied

good to hear.

 

post your solution for others.

Votes

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
Participant ,
Oct 24, 2020 Oct 24, 2020

Copy link to clipboard

Copied

LATEST

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();

Votes

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