Skip to main content
Inspiring
Nov 14, 2025 10:01 AM UTC
Answered

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

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
Peter Kahrel
Peter KahrelCorrect answer
Community Expert
Nov 14, 2025 11:19 AM UTC

> 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
Nov 14, 2025 11:19 AM UTC

> 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
)
Translate