7 Replies Latest reply on Oct 3, 2012 11:25 AM by wokoman1234

    Getting Anchor insertion point

    wokoman1234 Level 1

      Hi experts,

       

      Can someone tell me where I go wrong with below script ? Purpose is to release an inline anchored object, do something with the object, and put it back where it was originally.

       

       

      var myAnchor = app.selection[0];
      var myIP= myAnchor.insertionPoints[0] ; // should be the point where the current object is anchored on the doc
      var myAnchorPosition = myAnchor.anchoredObjectSettings.anchoredPosition;
      
      
      with (myAnchor)
      {
           // make custom so it can be released
           anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored;
           anchoredObjectSettings.releaseAnchoredObject();
        
          // ============================
          // do some stuff with the object ...
          // ============================
      
      
          anchoredObjectSettings.insertAnchoredObject(myIP, myAnchorPosition);
      }   
      
      

       

      I'm using CS6, and found similar scripts as above here but it fails to work, I'm getting error 'Object does noet support the property or method insertionPoints' ... So my question is : How to get a reliable way to store an anchors current insertion point, so we can place a reworked object back later.

       

      Thanks,

      K.

        • 1. Re: Getting Anchor insertion point
          Marc Autret Level 4

          An anchored object is the child of a Character (not InsertionPoint).

          So, assumed that the anchored object is selected, you'll have:

           

          var myAnchoredFrame = app.selection[0];

          var myParentChar = myAnchoredFrame.parent;

           

          Then you can work with that character (move, duplicate, etc.)

           

          @+

          Marc

          • 2. Re: Getting Anchor insertion point
            wokoman1234 Level 1

            Thanks, this way I at least understand why I get the error. But still failing to get what I want

             

            I don't really need to deal with the character itself, but with the object itself. In my case this is a group of elements, containing an image and some textboxes. So what I do first is release the object, ungroup, tag all elements and regroup. That's all working fine now, but then I want to have this group anchored again on exact the same location as it was before. So what would be the way to do that if I would have the parent selected ?

            • 3. Re: Getting Anchor insertion point
              Jump_Over Level 5

              Hi,

              I suggest to catch myParentChar.index before removing anchor.

              You can go back later to the right place using

              story.characters.item(index).insertionPoints[0];

              to anchor your group back there.

               

              hope..

              • 4. Re: Getting Anchor insertion point
                Marc Autret Level 4

                Here is a draft (ID CS5.5 and later):

                 

                 

                var obj = app.selection[0]; // assumed that obj is an anchored obj
                
                var ip = obj.parent.insertionPoints[0],
                    ancPos = obj.anchoredObjectSettings.anchoredPosition,
                    a;
                
                with( obj.anchoredObjectSettings )
                    {
                    anchoredPosition = AnchorPosition.ANCHORED; // needed to release
                    releaseAnchoredObject();
                    }
                
                if( obj instanceof Group )
                    {
                    // Keep the items refs to allow breakin the gp
                    // ---
                    a = obj.pageItems.everyItem().getElements();
                    
                    // Ungroup
                    // ---
                    obj.ungroup();
                    obj = null;
                
                    // Make some changes
                    // ---
                    with( a[a.length] = a[0].duplicate() )
                        {
                        move(undefined, ['50pt','50pt']);
                        rotationAngle = 15;
                        // etc.
                        }
                    
                    // Recreate a group
                    // ---
                    obj = a[0].parent.groups.add(a);
                    }
                
                // Re-anchor the object
                // ---
                obj.anchoredObjectSettings.insertAnchoredObject(ip, ancPos); // C5.5 and later
                

                 

                 

                @+

                Marc

                • 5. Re: Getting Anchor insertion point
                  wokoman1234 Level 1

                  Thanks again Marc, appreciate the effort. Problem is that I already tried something similar as above (be it in a bit less elegant format...) but then I get an error message stating invalid value for parameter storyOffset of method insertAnchoredObject. Expected InsertionPoint but received nothing. 

                   

                  I've done some further testing and it looks like the positioning of the anchorpoint plays a role. So if I explain my setup it may lead to an answer...

                   

                  My anchor is placed in a table cell, without any other additional content. This way there is a single story in the cell, and the anchor is linked to the end of the story. Under this circumstances the script doesn't work, and I get above stated error message.

                   

                  However, as soon as I add an additional character after my anchor (or just an empty space), the script works perfectly...

                   

                  Any idea what is causing this behaviour ? I guess I could modify the script to add a character first , run the script, and remove the extra character again but that seems rather over complicated

                  • 6. Re: Getting Anchor insertion point
                    Marc Autret Level 4

                    Ah! In the case you're working within a Cell you probably have to deeply resolve the insertion point specifier first—as this has been already discussed in recent topics.

                     

                    So, in my previous snippet, simply replace:

                     

                    var ip = obj.parent.insertionPoints[0],

                     

                    by

                     

                    var ip = obj.parent.insertionPoints[0].getElements()[0],

                     

                    This should solve the issue.

                     

                    @+

                    Marc

                    • 7. Re: Getting Anchor insertion point
                      wokoman1234 Level 1

                      Great! Thanks Marc