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.

AppleScript

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

ExtendScript

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();
y0=eFrame.geometricBounds[0]; 
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.

Considerations

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

AppleScript

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

ExtendScript

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
http://www.yourscriptdoctor.com/BlogRetrieve.aspx?BlogID=18153&PostID=1478487&A=Trackback
Trackbacks
Post has no trackbacks.

Recent Posts


Tags

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

Archive