6 Replies Latest reply on Jun 2, 2016 4:24 AM by HiroyukiSato

    zOrderPosition error caused by 'duplicate' and 'move' methods

    HiroyukiSato

      I created some paths and grouped them with a script.  Then I selected an item below them and tried getting zOrderPosition of it with a script. And I got an error.

      Is there a way to get rid of this?

       

      Here is a code.

      Please select a path and run test1 or test2 twice.  You'll get an error at the second time.

      (Tested with Ai CS3 and CC 2015)

      Thanks.

       

      function test1(){  // error (at the second time)

          var lay = activeDocument.activeLayer;

          var group = lay.groupItems.add();

          var p1 = lay.pathItems.ellipse(100,100,10,10);

          var p2 = p1.duplicate();

          var p3 = p1.duplicate();

         

          p2.move(group, ElementPlacement.PLACEATEND);

          p3.move(group, ElementPlacement.PLACEATEND);

         

          alert(activeDocument.selection[0].zOrderPosition);  // error

      }

       

      function test2(){  // error (at the second time)

          var lay = activeDocument.activeLayer;

          var group = lay.groupItems.add();

          var p1 = group.pathItems.ellipse(100,100,10,10);

          var p2 = p1.duplicate();

         

          alert(activeDocument.selection[0].zOrderPosition);  // error

      }

       

      function test3(){  // NO error

          var lay = activeDocument.activeLayer;

          var group = lay.groupItems.add();

          var p1 = lay.pathItems.ellipse(100,100,10,10);

          var p2 = p1.duplicate();

         

          p2.move(group, ElementPlacement.PLACEATEND);

         

          alert(activeDocument.selection[0].zOrderPosition);  // NO error

      }

       

      test1();