Copy link to clipboard
Copied
Hi, i would like to make a script that place an existing rectangle in a story as an anchored object.
I can't find a way to replicate the manual way (cut and past at an insertion point in a story) or find a command that would do it directly…
I develop in Applescript, but if you know how to do it in Javascript, i'll handle the translation 😉
Thanks for your help!
Hi Vincent,
look into the method insertAnchoredObject() of the anchoredObjectSettings of a rectangle.
This method has two arguments:
[1] storyOffset
[2] anchoredPosition
storyOffset is an insertion point, e.g. the first one of a text frame.
anchoredPosition is an enumerator of type AnchorPosition.
InDesign has three different ones:
AnchorPosition.ABOVE_LINE
AnchorPosition.ANCHORED
AnchorPosition.INLINE_POSITION
To anchor the first rectangle to the first insertion point of the first text frame
...Copy link to clipboard
Copied
Hi Vincent,
look into the method insertAnchoredObject() of the anchoredObjectSettings of a rectangle.
This method has two arguments:
[1] storyOffset
[2] anchoredPosition
storyOffset is an insertion point, e.g. the first one of a text frame.
anchoredPosition is an enumerator of type AnchorPosition.
InDesign has three different ones:
AnchorPosition.ABOVE_LINE
AnchorPosition.ANCHORED
AnchorPosition.INLINE_POSITION
To anchor the first rectangle to the first insertion point of the first text frame on page one:
var doc = app.documents[0];
var firstPage = doc.pages[0];
var firstTextFrame = firstPage.textFrames[0];
var firstRectangle = firstPage.rectangles[0];
// Anchor the rectangle:
firstRectangle.anchoredObjectSettings.insertAnchoredObject
(
// Argument storyOffset
firstTextFrame.insertionPoints[0] ,
// Argument anchoredPosition
AnchorPosition.ANCHORED
);
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thanks for the quick reply and for guiding me in the right direction!
I should have searched in the dictionary for "insert“ or "anchored", i guess it didn't cross my mind at the time 😉
Thanks again for your help.
Copy link to clipboard
Copied
Object>anchored object>insert.
This brings up a dialog box to insert an empty frame.
Copy link to clipboard
Copied
Hi guys,
i played a little with the "Insert Anchored Object" command (same as method in JS?) and the property "Anchored Object Settings" with no luck for now…
@Laubender: you say that "Insert Anchored Object" is a method of the property "Anchored Object Settings" of a rectangle. But in the Applescript dictionary of InDesign (CC 2021), commands don't belong to properties. So i don't know what to do with your answer. Maybe that's one of the many differencies between the two languages. See attached below a capture of the defintion of the command in Applescript.
@Eugene Tyson: i didn't know that UI command for creating anchored objets at the insertion point, even with specifying an object style. Good discovery! I would like to use that command in Applescript, but i can't figure how to translate it in Applescript. My bet was to use the "Insert Anchored Object" command (see capture of the description of the command) but i block on how to express the "Anchored Object Settings" required parameter.
So, in less words, i'm still lost, even if i can't be that far of the solution…
tell application "Adobe InDesign 2021"
tell myDoc
set myObject to insert anchored object (anchored object setting of myDoc) story offset insertion point -1 of myStory
end tell
end tell
Copy link to clipboard
Copied
Sorry, I did not look into your screenshot before sending my last post.
But here you have all pieces of the puzzle:
The command and the two arguments story offset ( which means a insertion point! ) and the enumeration, the anchored position. With the exact syntax I cannot help, but using AppleScript for anchoring a rectangle must work!
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
So, it worked. It seemed that i didn't tried all the possible combinations to make it work!
Your two last replies have encouraged me to dig deeper, and i thank you for that, even if it's way to late now here in paris, France 😉
Here is the equivalent of your script in Applescript, given that the object and the story (i prefer those to the text frame in a lot of cases) are already known:
tell application "Adobe InDesign 2021"
tell myDoc
insert anchored object anchored object settings of myRectangle story offset insertion point -1 of myStory
end tell
end tell
Copy link to clipboard
Copied
Hi Vincent,
I'm glad it's working for you now!
FWIW: We are in the same time zone.
I'm in Würzburg, Germany.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
noted for the time zone 😉
good day to you!
Copy link to clipboard
Copied
Hi Vincent,
I hope, you tested my ExtendScript code on a document where one rectangle and one text frame is on page one.
For the differences ExtendScript vs AppleScript:
The undelying structure of the DOM should be nearly or exactly the same. So should be the dependencies. Also in AppleScript there is a rectangle object and a text frame object. The rectangle object should have anchored object settings and this should have methods like insert anchored object or release anchored object.
Maybe someone with AppleScript expert knowledge stops by and can tell more.
I'm just the ExtendScript guy. See DOM description for ExtendScript here:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#AnchoredObjectSetting.html#d1e385380
Hm, wait! Are you using a very old version of InDesign? Perhaps InDesign CS5 or below?
Then method insertAnchoredObject() was not available. It was added with InDesign version 7.5.
Regards,
Uwe Laubender
( ACP )