Skip to main content
Inspiring
November 14, 2025
Answered

How to Insert a Rectangle Frame Tool Inside a Text Frame in InDesign

  • November 14, 2025
  • 1 reply
  • 61 views

Hi sir
I was trying to insert a rectangle frame tool inside a text frame using this code 

const selectedTextFrame = doc.selection[0];
const page = selectedTextFrame.parentPage;
const rect = page.rectangles.add({
geometricBounds: [0, 0, 100, 100],
});
This code creates the rectangle, but it does not place it inside the text frame
Correct answer Peter Kahrel

it does not place it inside the text frame

 

That's because you place it on the page, not in the frame. You should then move the rectangle into the frame (it's not possible to place a rectangle into a text frame directly). Add this to your script:

 

rect.anchoredObjectSettings.insertAnchoredObject (
  selectedTextFrame.insertionPoints[0],
  AnchorPosition.INLINE_POSITION
)

1 reply

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
November 14, 2025

it does not place it inside the text frame

 

That's because you place it on the page, not in the frame. You should then move the rectangle into the frame (it's not possible to place a rectangle into a text frame directly). Add this to your script:

 

rect.anchoredObjectSettings.insertAnchoredObject (
  selectedTextFrame.insertionPoints[0],
  AnchorPosition.INLINE_POSITION
)