Skip to main content
Participant
October 5, 2013
Question

Parsing only visible path items

  • October 5, 2013
  • 1 reply
  • 1618 views

Hello World!

I am currently working on a script which is parsing all the page items on artwork .

Everything seem perfectly fine, except for the left over path items.

Lets say, I have already succed to parse and hide, for eg. compound path items, raster items, text frames, and so on. The only things left are the simple path items.

We all know that path items, can be a part of compound path, but these ones we have already sorted out including their subpath items, so some of them are already !editable / !visible. 

paths = activeDocument.pathItems;

for (index = 0; index < paths.length; index++) {

   if (paths[index].editable) {

   ...

   }

}

The simple way of parsing so many path items as shown above is taking a lot, lot of time.

In compare to checking for all other types of objects, it is like 90% of time required to execute the script, and thats no good. 

I dont want to parse as much as like 15-25k paths in order to check if some of them are still visible or editable, and my question is:

Is there any other way to get a collection of visible paths items only?

Thanks in advance,

Igor

This topic has been closed for replies.

1 reply

Inspiring
October 5, 2013

Hi

Do not know the purpose of your script (so why you are analyzing every items). You could, for example, instead of calling all item kinds separatelly (pathItems, compoundPathItems and so on), try:

var items = app.activeDocument.pageItems;

So..when you execute the loop (your "for" statement), it would go right to each specific object.

Another way is, when you evaluate your pathItem in the "for" statement, you can include:

paths = activeDocument.pathItems;

for (index = 0; index < paths.length; index++) {

   if (paths[index].editable && paths[index].parent.typename != "CompoundPathItem") {

   ...

   }

}

This would evaluate if the pathItem is not part of a compoundpath. If it´s true, then it does not enter to the if

Tell me if that helps

Gustavo.

Participant
October 5, 2013

Thanks for your reply, you're right.

Purpose of my script is to analyze drawings sent by our customers and replace PMS colors into our own adjusted colors.

There would be no problem if people would not make mistakes, but as we know - they do.

This is the main reason why I have to analyze every single item on artwork for if it is a CMYK, RBG, LAB or SPOT color, and for what are the values of certain color.

I have already optimized and simplified my script as much as I could but still, checking as many as ~20k path items for if it is "editable" or a part of compound path is taking a lot of time (about 2-3 minutes). Not saying about analyzing the color itself.

I was wondering if there is any other way to reduce number of objects to check, especially if some of them are already sorted out.

Inspiring
October 5, 2013

Hi beOpenMinded

How about if you try to direct analyze if the pathItem is visible?

paths = activeDocument.pathItems;

for (index = 0; index < paths.length; index++) {

   if (! paths[index].hidden) {

   ...

   }

}

About your question in first comment: Is there any other way to get a collection of visible paths items only?

One way you could try to do it is to work with an array, then, instead of analyzing all the pathItems in the artwork, you can analyze only the items in the array. For example:

var paths = app.activeDocument.pathItems;

var visiblePaths = new Array();

for (var g=0; g<paths.length ;g++){

     if (! paths.hidden){

          visiblePaths.push (paths); //so, if this path is visible, then include in the array;

     };

};

// now you work with the objects collected in the array:

for (g=0; g<visiblePaths.length ;g++){

//...

};

----

Does it make any difference?