7 Replies Latest reply on Oct 6, 2013 1:45 AM by BeOpenMinded

    Parsing only visible path items

    BeOpenMinded

      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

        • 1. Re: Parsing only visible path items
          Gustavo Del Vechio Level 3

          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.

          1 person found this helpful
          • 2. Re: Parsing only visible path items
            BeOpenMinded Level 1

            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.

            • 3. Re: Parsing only visible path items
              Gustavo Del Vechio Level 3

              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[g].hidden){

                        visiblePaths.push (paths[g]); //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?

              1 person found this helpful
              • 4. Re: Parsing only visible path items
                Gustavo Del Vechio Level 3

                Also, another way to try is like a direct way:

                 

                var items = app.activeDocument.pageItems; //so it returns an array of all the Items directlly.

                 

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

                    if (items[g].filled){

                         //...when the pageItem is a placedItem, a meshItem or any that does not support fill, it would not enter here since it would return undefined in the evaluation instead of true.

                     };

                };

                 

                Gustavo.

                • 5. Re: Parsing only visible path items
                  BeOpenMinded Level 1

                  Again, you're right.

                  I have also already tried this way of making it works. Does not make any change

                   

                  Try to copy and paste like 20k of path items with different fills, strokes, and gradient keys on your artwork. Then try to analyze it.

                  Simple fact of checking for attributes of so many objects is taking a lot of time.

                   

                  Does not make any difference if half of these objects are hidden (already sorted out), or not.

                   

                  Thuoght there might be some other super-fast way of getting collection of defined visible objects.  

                  • 6. Re: Parsing only visible path items
                    Gustavo Del Vechio Level 3

                    Yeah if you have too much items in the artwork it would take time to loop through each item.

                     

                    My suggestion to direct analyze if the item is filled in last comment was exactelly to find a way to jump some items in the collect. Perhaps a direct call "if" the item has the color you want to change could speedy a little the process.

                     

                    But, anyway, no, I do not know any super-fast way of solving the task. And, if I´m not missing the obvious, Illustrator manual does not mention any way to get directlly the visible paths.

                     

                    If you find a good way, please publish here. I´d like to learn too.

                     

                    Best Regards

                    Gustavo.

                    • 7. Re: Parsing only visible path items
                      BeOpenMinded Level 1

                      Yeah, looping through collection of 10000 path items alone (just looping, doing nothing) takes about 12-15 seconds.

                      Just one "if" statement for any given paths attribute inside this loop takes another 12-15 seconds.

                       

                      I have spent a lot of time doing measurments and stuff, to figure out how to make it faster

                       

                      Direct analyze for if the item is filled or stroked is no good.

                      It takes approx. same amount of time as direct checking for the color ([NoColor] == nothing to check), and you still have to perform another check for colortype if you want to analyze values of different colortypes.

                       

                      In order to optimize execution of your scripts you have to reduce the number of checkings to minimum.

                      For eg. instead of checking twice for if the object is hidden or locked, you can check if the object is editable and save you some time.

                      This is why I designed my script to hide processed items from view and then check only for if it editable, instead of checking numbers of other attributes for different types of objects.

                       

                      And yeah, I have also could not find a direct way to get collection of visible paths in manual. Still looking forward to get it done

                      Thanks for your support anyway

                       

                      Edit:

                      I have just found out that running a script is taking only about 20% of CPU power.

                      Is there any way to involve certain amout of processing power, increase it?