5 Replies Latest reply on Jan 11, 2012 6:34 AM by Harbs.

    [JSX] Bug in property "allPageItems" of object "layer"?

    Laubender Adobe Community Professional & MVP

      Hi, all!

       

      I suppose there is a bug in the "allPageItems" property of the layer object.
      As I understand this property it should include realy ALL page items; also page items on master pages.


      But this seems not the case.


      Example:

      Given an InDesign file with one regular page, one layer, two master pages A.
      There are 3 rectangles on master pages A, NO objects on regular page 1.

       

      If you run the following script, "allPageItems" returns the same result as "pageItems" when used with layers[0].

       

      //TESTED IN: CS3 (5.0.4) Mac OSX 10.6.8
      //TESTED IN: CS4 (6.0.6) Mac OSX 10.6.8
      //TESTED IN: CS5 (7.0.4) Mac OSX 10.6.8
      //TESTED IN: CS5.5 (7.5.2) Mac OSX 10.6.8
      
      var d = app.documents[0];
      
      //CONTROL:
      $.writeln(d.allPageItems.length);//Result: 3 (There are 3 rectangle objects on master pages A, no objects on regular pages)
      
      $.writeln(d.layers[0].allPageItems.length); //Result: 0 ( ??? Shouldn't that include master page items?)
      $.writeln(d.layers[0].pageItems.length);//Result: 0 (There are no page items on regular pages)
      

       

      Conclusion: we cannot use the length property of allPageItems of the layer object to determine if a layer is empty!
      If you do so you are risking to delete master page items when you presume your layer is empty (length of layer.allPageItems is zero) and remove it.

       

      For me there seems to be a bug in allPageItems of the layer object.
      I'm on Mac OS X 10.6.8.

       

      Can anyone confirm that?
      Or test the allPageItems property in other scripting languages or on MS Windows?

       

      Uwe

        • 1. Re: [JSX] Bug in property "allPageItems" of object "layer"?
          Marc Autret Level 4

          Hi Uwe,

           

          I'm not sure this is a 'bug,' I think this is a design choice. The Layer object is a view and, indeed, it does not see master page items. I agree with you that this may be confusing, but there are pros and cons on this issue. If the Layer.pageItems collection had been designed to include both regular page items and master page items, it would also be misleading, especially when we have to deal with overriden objects originated on a master spread. Note that in the InDesign GUI, the Layers panel only displays regular page items, unless you explicitly select a master spread in the Pages panel (in which case the Layers panel only displays the master page items). It makes sense to me that these two levels are not mixed.

           

          As a consequence, myLayer.pageItems (and myLayer.allPageItems) can be empty—in the sense that no regular page item is instantiated on that layer—although the master spreads may contain page items whose itemLayer is myLayer. So, if you need to check whether myLayer is empty at the master level, you probably have to look if it belongs to myDoc.masterSpreads.everyItem().pageItems.everyItem().itemLayer

           

          @+

          Marc

          • 2. Re: [JSX] Bug in property "allPageItems" of object "layer"?
            Laubender Adobe Community Professional & MVP

            Hi, Marc!
            Thank you for commenting. Indeed I was a little confused ;-)

             

            After thinking about it and doing some testing:

            On document level pageItems and allPageItems will find objects on regular pages AND master pages.
            (allPageItems will find anchored objects, pageItems will not)

             

            On layer level we have the principal division between regular spreads and master spreads.

             

            So if we have to make sure a particular layer is empty, we have to do two checks:

             

            1. check if: doc.mylayer.pageItems.length = 0

            2. loop through all pageItems on master pages and looking if the itemLayer property is equal to the particular layer we want to remove

             

            In that case we do not need to use allPageItems, because there are no anchored objects without an object they are anchored on.

             

            Thank you for clarification…

             

            Uwe

            • 3. Re: [JSX] Bug in property "allPageItems" of object "layer"?
              Harbs. Level 6

              Hi Marc,

               

              I'm not sure I agree with you.

               

              Master Page Items can exist on different layers as well, so I don't see why layers applies to local pages any more than master pages. Layer collection are not limited to a specific page.

               

              When a master page item is overridden, what actually happens under the hood is that the master page item is COPIED to the local page and a reference to the master page item is kept. So when you override the master page item, you actually have multiple copies (and each one can be moved to a different layer).

               

              To me it makes much more sense for the collection to return all items, and you can filter out "obj.parent instanceof MasterSpread" if you want.

               

              I'd log it as a bug...

               

              Harbs

              • 4. Re: [JSX] Bug in property "allPageItems" of object "layer"?
                Marc Autret Level 4

                Hi Harbs,

                 

                I totally understand your point, but I still think that the Layer.pageItems collection has been deliberately designed to focus on regular page items. In many scripts this is the behavior we implicitly expect from it, as we usually don't want to retrieve master components when we are retrieving layer items. Anyway I could be wrong. Only Adobe devs can tell us whether it is a bug, or a design choice.

                 

                @+

                Marc

                • 5. Re: [JSX] Bug in property "allPageItems" of object "layer"?
                  Harbs. Level 6

                  I'll file it as a bug, and see what happens...

                   

                  (Or will that mess up your scripts?)

                   

                  Harbs