Automating Adobe InDesign CC 2015

Inline Text Frames

Monday, October 31, 2016

Inline Text Frames

An interesting topic was brought to light recently in the script forum for Adobe InDesign. It had to do with inline text frames.

Inline text frames may also be referred to as anchored frames as they are not necessarily anchored "in line".

No matter how they are referenced, inline frames can pose particular problems especially when it comes to styling the frame.

Consider the problem posed by the person in the script forum:
"Write an arbitrary number of textlines in a textframe. After the last textline, "embed" another inner textframe with border in the textframe and write another line of text in this textframe."

This is simple enough, but should there need to be a specified amount of space between the text and the frame; or perhaps the frame needs to be a specified width and centered within its containing text, some difficulty can arise. In fact, the inquirer further states:
"I can't find out how to get the positions for my inner textframe. My only idea was to use the move method..."

To do all of this manually would require a number of steps, including cutting and pasting the frame, and finally, setting properties. If there are to be a number of such frames to be created, a script can save some tedious steps.

Inline Text Frame Properties

First and foremost, an embedded text frame assumes the styling of its parent. Therefore, if an insertion point is used to create or place the frame, the styling in effect for the insertion point is inherited by the text frame. Some of the styling attributes to consider would be the following:

  • justification: left align, centered, or right align
  • indents and spacing: space before and space after, left or right indent

Since these are properties of a paragraph style, it is advisable to have a paragraph style established with these properties set. Even if placing the inline text frame manually, an empty paragraph set to the designated paragraph style eliminates some steps when placing.

With or without a predefined paragraph style, a script can provide a welcome solution.

Sample Scripts

The following sample scripts not only provide a solution to the inquiry posed above, but also establish spacing and justification attributes for the embedded text frame and its contents.


set frameDepth to 10
set frameWidth to 85
set leftInset to 2
set topInset to 2
set str to "some text in first line"
set str to str & "
" --new line character
set str to str & "some text in second line"
--last line of main string needs hard return
set str to str & return
set nContent to "This is content for inner frame"
tell application "Adobe InDesign CC 2015"
	set measurement unit of script preferences to millimeters	
	set pageRef to page 1 of document 1
	tell pageRef
		set tFrame to make text frame with properties {geometric bounds:{10, 10, 100, 100}, contents:str}
	end tell
	set insertRef to insertion point -1 of tFrame
	set y0 to baseline of insertRef
	set x0 to horizontal offset of insertRef
	tell insertRef
		set properties to {space before:topInset, left indent:leftInset}
		set eFrame to make text frame with properties {geometric bounds:{y0, x0, (y0 + frameDepth), (x0 + frameWidth)}, stroke weight:"2 pt", fill color:"None", text frame preferences:{vertical justification:center align}}
	end tell
	set eFrameInsert to insertion point 1 of eFrame
	set properties of eFrameInsert to {justification:center align, contents:nContent}
end tell


var frameDepth = 10;
var frameWidth = 85;
var leftInset = 2;
var topInset = 2;
var str  = "some text in first line";
str += "\n";
str += "some text in second line";
//last line of main string needs hard return
str += "\r";
var nContent = "This is content for inner frame";
app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
var pageRef = document.pages.item(0);
var tFrame = pageRef.textFrames.add();
tFrame.geometricBounds = [10, 10, 100, 100];
tFrame.contents = str;
var insertRef = tFrame.insertionPoints[-1];
insertRef.spaceBefore = topInset;In
insertRef.leftIndent = leftInset;
var eFrame = insertRef.textFrames.add();
x0 =(eFrame.geometricBounds[1] + leftInset);
eFrame.geometricBounds = [y0, x0, y0+frameDepth, x0+frameWidth], 
eFrame.strokeWeight = "2 pt";
eFrame.fillColor = "None";
eFrame.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
eFrameInsert = eFrame.insertionPoints[0];
eFrameInsert.justification = Justification.CENTER_ALIGN;
eFrameInsert.contents = nContent;

Using last insertion point

Script Refinements

Using an object style for the anchored frame as well as a paragraph style for its parent would simplify the script considerably. Also adding a custom dialog box from which the user could determine settings for the text as well as the inline frame and its contents would make the scripts more versatile.


The requirements posed by the inquiry above leaves a question unanswered: what then? Would the user want to continue to add more text after the inline frame, or perhaps repeat the same scenario below?

One problem I see would be in adding text below the inline frame. A user not familiar with inline text frames may have a problem accessing the text insertion point after the inline text frame. If the page design requires text to follow the inline text frame, a slightly different approach to the script aboe would be required. Here, instead of using the last insertion point (insertion point -1), the script could possibly insert a blank paragraph and use the first insertion point of the blank paragraph for inserting the text frame.

To use a blank paragraph, substitute the code below for the text string (str):


set str to "some text in first line"
set newContent to "More text to add"
set str to str & "
" --new line character
set str to str & "some text in second line" 
set str to str & return
set str to str & return --empty paragraph created
set str to str & newContent & return

Then define the value for the insertion point (insertRef) relative to the empty paragraph:

set insertRef to insertion point 1 of paragraph 2 of tFrame


var str  = "some text in first line";
str += "\n";
str += "some text in second line" + "\r";
str += "\r"; //empty paragraph created
str += "New content to add" + "\r";

And for the insertion point reference:

var insertRef = tFrame.paragraphs[1].insertionPoints[0];

Using empty paragraph

Script Notes:

Notice that both scripts set the measurement unit for script preferences. This sets the measurement units for the script without touching the measurement units set for the document. I can't image writing a script that performs any mathematical computation without setting this to my preferred measurement unit: either points or millimeters.

Onward and Upward

By using the combined power of paragraph styles and object styles, with or without a script, you can eliminate a lot of otherwise necessary steps for inserting text frames within a story flow.

Trackback Link
Post has no trackbacks.

Recent Posts


scripting file paths enable redraw Metadata CALS tables Fixed Layout ePub repeat loops Find Change Automating animations with timeout object styles try/on error lists AppleScript Sound transformation matrix Create Text Frame XML structure arrays Excel PDF Media import HTML Export HTML watermark say integer editboxes Find by Color Character Styles entire path Video dropdowns images new document Table cells do script transform again Border Panel resize Index of blogs and scripts for year 2016 Caption Variable functions parent import text Nested Styles Read text file as list Adobe InDesign CC Fixed Format ePub Glossary measurement editboxes Preferences GPS metadata Custom Dialog reframe folder selection Adding Captions External Object Scripts placeable save template text item delimiters page items InDesign CC HTML Export Placing images automating InDesign Document from Template AppleScript dialogs Document Presets text placement handlers user interaction level records metacharacters XML script folder import XML text editbox pasteboard cut and paste Choose from list path trimText Apple apps coordinates Bullets Custom Buttons measurements Checkbox Control resolve Custom CSS Style Sheets PDF export preferences automation BrdgeTalk parent page Image Placement fit Autoflow Publish Online directory AppleScript Templates tutorial Text Cleanup Embed Document stylesheets Styling Text InDesign dialogs Templates script templates Create Document PDF security image metadata wild cards XML tags Export to PDF ePub for iPad Change Text Find by Font Radiobutton Group find change options Combobox automated workflow Enabling Groups if/then Editbox text concatenation Mail Find by Attribute CSS ePub for Kindle Tables Script Preferences Numbering massage text Interactive Publications doScript active spread Choose file Repeat With transform styles Document stylesheets InDesign template Hyperlinks Library Folder System Events Find Text paragraph styles GPS table styles