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

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

Archive