Skip to main content
Jeen
Participant
June 19, 2014
Answered

How to select open path objects not include no filled objects?

  • June 19, 2014
  • 2 replies
  • 1898 views

I use CS6.

I want to select open path objects, but not include no filled objects.

That means if these objects with open path and filled any color or gradient, I want to select them.

Now I can select objects with open path.

var doc = app.activeDocument;

doc.selection = null;

numClosed = 0;

for ( var i = 0; i < doc.pathItems.length; i++ )

{

    if ( ! doc.pathItems.closed )

    {

        doc.pathItems.selected = true;

        numClosed++;

    }

}

alert(numClosed + " paths open.");

But how to not include no filled shapes?

Anybody know?

Thank you.

This topic has been closed for replies.
Correct answer pixxxelschubser

Hi @jeen,

if you want to select only open paths with any fill color, you can replace this line:

if ( ! doc.pathItems.closed)

with this:

if ( ! doc.pathItems.closed && doc.pathItems.filled == true)

Have fun

2 replies

Inspiring
January 12, 2023

Is anyone able to get this to work in modern CC apps? I keep getting an error that of no such element for line 6 "!doc.pathItems.closed"

My test file definitely contains broken paths.

var doc = app.activeDocument;
	doc.selection = null;
	numClosed = 0;

	for (var i = 0; i < doc.pathItems.length; i++) {
		if (!doc.pathItems.closed) {
			doc.pathItems.selected = true;
			numClosed++;
		}
	}
alert(numClosed + " paths open.");

 

femkeblanco
Legend
January 12, 2023

Moving to the present forum caused loss of indices in loops. Change

		if (!doc.pathItems.closed) {
			doc.pathItems.selected = true;

to

		if (!doc.pathItems[i].closed) {
			doc.pathItems[i].selected = true;
Inspiring
January 12, 2023

This works perfectly. Thank you!

Revised and functioning properly in Illustrator CC 27.1.1:

var doc = app.activeDocument;
	doc.selection = null;
	numClosed = 0;

	for (var i = 0; i < doc.pathItems.length; i++) {
		if (!doc.pathItems[i].closed) {
			doc.pathItems[i].selected = true;
			numClosed++;
		}
	}
alert(numClosed + " paths open.");

 

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
June 19, 2014

Hi @jeen,

if you want to select only open paths with any fill color, you can replace this line:

if ( ! doc.pathItems.closed)

with this:

if ( ! doc.pathItems.closed && doc.pathItems.filled == true)

Have fun

Jeen
JeenAuthor
Participant
June 20, 2014

Wow!~It works!

Thank you so much!