2 Replies Latest reply on Jul 28, 2014 2:46 PM by myDavey

    Looping through objects - testing links

    myDavey Level 1

      Hi

      I have a script that moves all instances of a linked object according to user defined X,Y values.

      In order to do this, I need to loop through all objects with links

      What is the best way to do this?

       

      As of now, this is what I am doing:

      var g = myDoc.allGraphics;
      for (var i=0; i<g.length; i++) {
           if (g[i].itemLink.name == USER_LINK) {
                g[i].parent.move(undefined, [USER_X, USER_Y]);
           }
      }

       

      It works well, however I ran into some problems where link was null

      Also, is it always the graphic that is linked, or can its parent be linked as well?

      If not, then I can just condition that if itemLink == null - continue

       

       

      Any advice and guidance would be much appreciated

      Thanks

      David

        • 1. Re: Looping through objects - testing links
          Jump_Over Level 5

          It works well, however I ran into some problems where link was null

           

          if (g[i].itemLink && g[i].itemLink.name == "USER_LINK")     //     should be enough
          
          

           

          Also, is it always the graphic that is linked, or can its parent be linked as well?

          Graphic can be linked ==> itemLink !=null and itemLink.status can vary

          or pasted ==> itemLink == null.

           

          As far as I know graphic.parent can not be linked.

           

          However not every linked graphic.parent can be moved. I e. those one which are anchored with

          AnchorPosition.INLINE_POSITION and AnchorPosition.ABOVE_LINE

           

          Above case can be a source of error as well.

          Consider also locked object or locked entire layers.

           

          Jarek

          • 2. Re: Looping through objects - testing links
            myDavey Level 1

            Hi Jarek

            Thanks again!

             

            I forgot that in Javascript (and many others as well) the "and" statement works 1 piece at time

            Thanks for the information and help

             

            Regarding the locked objects/layers, I had taken care of that

            But not the anchored objects

             

             

            Thanks

            David