Skip to main content
Participating Frequently
July 31, 2025
Answered

Indesign script to get position of Note

  • July 31, 2025
  • 1 reply
  • 273 views

Hi community,

 

I am trying to write a script that includes anchoring an object to a pre-existing Note in Indesign.

I can get the anchoring to work, but I cannot figure out how to find the actual position of the Note within the parent textframe/Story, to use the Note as the anchor insertion point.

 

I have tried checking various properties of the Note, but note.insertionPoints[x] appears to return insertionPoints within the Note text, ditto note.characters. Note.storyOffset appears to return the beginning of the parent story. Note.parent returns a story object, nothing positional. 

 

If it's not possible to anchor to the note itself that's ok,  getting the neighboring text would be good enough, but I'm not sure how to get there?

 

Thanks in advance for your advice!

 

 

 

 

Correct answer Peter Kahrel

You can set the text frame's vertical position relative to the line (in which its anchor sits). If you didn't yet, use an object style, and apart from vertical position also set the frame's  width, (vertical) auto size, and whatever else.

 

> is there a way to create the textframe on the fly in relation to the insertion point

 

You can use this:

myTextFrame = myNote.storyOffset.textFrames.add ({
  // Any properties, probably
  appliedObjectStyle: myObjStyle,
  // and any other
});

 

1 reply

Peter Kahrel
Community Expert
Community Expert
July 31, 2025

The note object has a property storyOffset, which is the insertion point of the note's anchor.

Participating Frequently
July 31, 2025

Thank you Peter!


That seems correct, it looks like I was misinterpreting my problematic result... 

 

My problem is that even using myNote.storyOffset as the object InsertionPoint I am unable to vertically align my anchored textframe to be next to the Note.

 

When I am anchoring my object, I am using formulation:
myTextFrame.anchoredObjectSettings.insertAnchoredObject(myNote.storyOffset);

 

I am adding the myTextFrame object to the document prior to this line in the script, so that myTextFrame var is instantiated... and the initial location of the textframe _prior_ to the anchoring seems to become part of a default Y-offset. (I think that's what's happening?)

 

So the the anchored textbox is alway near the top of the page, regardless of my anchoredObjectSettings.verticalReferencePoint setting. It is anchored, but much too high on the page.
 
I thought of trying to create the text box at vertical coordinates corresponding to the Note, but when I try to get positional properties of myNote.storyOffset, I am getting an error: myNote.storyOffset.baseline gives error: "the property is not applicable in the current state"

 

Do you have any suggestions? Am setting up the anchor wrong, is there a way to create the textframe on the fly in relation to the insertion point (as in the GUI) instead of in advance?

 

(As your first answer was definitely correct I am happy to mark that and put this in a separate post as well:)

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
July 31, 2025

You can set the text frame's vertical position relative to the line (in which its anchor sits). If you didn't yet, use an object style, and apart from vertical position also set the frame's  width, (vertical) auto size, and whatever else.

 

> is there a way to create the textframe on the fly in relation to the insertion point

 

You can use this:

myTextFrame = myNote.storyOffset.textFrames.add ({
  // Any properties, probably
  appliedObjectStyle: myObjStyle,
  // and any other
});