9 Replies Latest reply on Jan 7, 2014 9:02 PM by Larry G. Schneider

    Accessing the elements of a page item

    ProfessorCal

      Good people of the Adobe forums,

       

      I am working on a script that performs a series of things on all of the artwork in a document.  At one point, it needs to compare the fill color of every item to a sample color.  The problem is, the artwork is a collection of compound path items and path items.  When I look for pathItems[x].fillColor, it works fine.  When I look for compoundPathItem[x].fillColor, it comes back undefined.  So, I've moved to looking at page items, but I seem to be unable to get to the internals on the page items.  If I have a compound path item, how would I address its properties from its parent page item?  I tried:

       

      pageItem[x].compoundPathItem.pathItems[0].fillColor,

      pageItems[x].fillColor,   & 

      pageItems[x].compoundPathItem.fillColor. 

       

      They all seem to break.

        • 1. Re: Accessing the elements of a page item
          Gustavo Del Vechio Level 3

          Hi

           

          The fillColor property is not valid for compoundPathItems. This is because the color of a compound path is determined by its interior paths. So, if you change the color of the paths inside a compound path, you actually change the color of the compound path. Consider the compound path like a structure, a container that takes the color of their components (its paths).

           

          This is why you get a return "undefined" when you try to read the "fillColor" of a compoundPathItem.

           

          Hope to be helped

          Best Regards

          Gustavo.

          1 person found this helpful
          • 2. Re: Accessing the elements of a page item
            Gustavo Del Vechio Level 3

            For example (did not test yet):

             

             

            var doc = app.activeDocument;
            var compounds = doc.compoundPathItems; //this will return an array of the CompoundPaths;
            
            
            for (var g=0 ; g<compounds.length ; g++){
               var interiorPaths =  compounds[g].pathItems; //it will give you an array of the paths inside the compoudPaths. So you can read the fillColor of the paths
               //now play with the interiorPaths array. You could declare here a new -for- statement to cycle between these paths.
            };
            
            

             

            This will allow you to work with the paths inside the compound paths.

             

            This is only one way to work. There's other ways also to work.

             

            Best Regards

            Gustavo.

             

            Message was edited by: Gustavo Del Vechio

            1 person found this helpful
            • 3. Re: Accessing the elements of a page item
              Gustavo Del Vechio Level 3

              P.S: I've just correct the above code.

               

              Gustavo.

              • 4. Re: Accessing the elements of a page item
                ProfessorCal Level 1

                Gustavo,

                 

                Thank you for your quick response!  Unfortunately, that doesn't address my big problem.  I will try to explain a bit better..

                 

                I know about having to access the path items inside of a compound path.  That's why I tried "pageItem[x].compoundPathItem.pathItems[0].fillColor" (first option listed in my first post)..  The tough bit is that it appear I need to work my way through all of the art in terms of page items, instead of looping through the path items separately and the compound path items separately.  This helps keep things in proper order as the script goes on, after comparing, to move the items to new groups that have to be in a specific order.

                 

                So, it brings me back to the problem of finding out the fill color of a page item whether it is a regular path item or a compound path item.

                • 5. Re: Accessing the elements of a page item
                  Gustavo Del Vechio Level 3

                  Hi ProfessorCal

                   

                  Thank you. I think I understand you. So you want to work by looping between all pageItems. An idea, perhaps could help: what about if you insert an "if" statement inside your loop, so it first analyzes the kind of pageItem, and you have different codes for the different kinds of items (like paths or compoundPaths). Example:

                   

                  if (pageItem[x].typename == "PathItem"){

                  //your code here.

                  };

                  else

                  if (pageItem[x].typename == "CompoundPathItem"){

                  //your code here

                  };

                   

                  Would it help your code?

                   

                  P.S: you could even evaluate if the current pathItem is inside or not any group. Example:

                   

                   

                  if (pageItem[x].typename == "PathItem" && pageItem[x].parent.typename == "Layer"){

                  //so its an isolated path not inside any group or compoundPath.

                  };

                   

                   

                  Abraços!

                  Gustavo.

                   

                  Message was edited by: Gustavo Del Vechio

                  1 person found this helpful
                  • 6. Re: Accessing the elements of a page item
                    ProfessorCal Level 1

                    Actually, that's exactly what we're doing.

                     

                    Later parts of the code have to look at the fill color of each item, check its type (gradient -vs- spot) and compare it to other colors.  In order to avoid a series of 'if' statements every time, we have made a function that takes each page item and returns a path item from it so we can work with that within the rest of the code (it's easier to write all of these comparisons if your'e always expecting to get a path item, and the first path item of every compound path has properties that apply to the entire compound path..) SO...  that function looks like this:

                     

                    function getLeadItem(glPage) {   //glPage is the Page Item

                        if (glPage.typename == 'CompoundPathItem'){

                            return glPage.pathItems[0]    //returns the first path item of the compound path (...but does not work)

                        } else {

                            return glPage  (if it is a normal page item, it just returns itself)

                        }

                        glPage = null

                    }

                     

                    for all of the page items that are regular path items, the code later on that looks like this:

                     

                    if(item.fillColor == '[GradientColor]'){

                                selectedColor = doc.activeLayer.pageItems[y].fillColor.gradient

                     

                    But any of the compound path ones break, which is why we made the function earlier, so that 'item' would ALWAYS be a path item, and not compound.

                    • 7. Re: Accessing the elements of a page item
                      CarlosCanto Adobe Community Professional & MVP

                      your function DOES work, are you dealing with Outlined text? text usually gets grouped once it's outlined

                       

                      var idoc = app.activeDocument;
                      var glPage = idoc.pageItems[0];
                      
                      var alert(glPage.typename);
                      var leadItem = getLeadItem (glPage);
                      
                      alert(leadItem.fillColor.typename);
                      
                      function getLeadItem(glPage) {   //glPage is the Page Item
                      
                          if (glPage.typename == 'CompoundPathItem'){
                      
                              return glPage.pathItems[0] ;   //returns the first path item of the compound path (...but does not work)
                      
                          } else {
                      
                              return glPage;//  (if it is a normal page item, it just returns itself)
                      
                          }
                      
                          glPage = null
                      
                      }
                      
                      • 8. Re: Accessing the elements of a page item
                        ProfessorCal Level 1

                        Carlos, Gustavo,

                         

                        Thank you both for the help.  Looks like I was misinterpreting my error messages.  The problem seems to have more to do with the way data is being fed to the function and how our list of page items is changing over time as other parts of the code move things around.

                         

                        Thanks again.

                        • 9. Re: Accessing the elements of a page item
                          Larry G. Schneider Adobe Community Professional & MVP

                          Then you may need to start at the back and work forward which reduces the chances of changing the index of the page item.