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


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