Skip to main content
October 3, 2012
Answered

Getting Anchor insertion point

  • October 3, 2012
  • 1 reply
  • 2007 views

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.

This topic has been closed for replies.
Correct answer Marc Autret

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


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

1 reply

Marc Autret
Legend
October 3, 2012

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

October 3, 2012

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 ?

Jump_Over
Legend
October 3, 2012

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..