InDesign compose and formatting text frame

I have to compose and formatting text frame with data from DB.

I know how to solve this generating a txt file with InDesign tags and place it inside text frame but i’m curious if is possible to generate all in memory and apply at the end to text frame.

Something like:

tell application “Adobe InDesign CS6”
tell active document
set frameRef to item 1 of selection – this is only for example
tell insertion point -1 of frameRef
set applied paragraph style to “Title”
set contents to “First Title line” & return & “Second Title line”
end tell
tell insertion point -1 of frameRef
set applied paragraph style to “Text”
set contents to “Text line 1” & return & “Text line 2.”
end tell
end tell
end tell

But more reliable. Something like define properties of text frame where contents is defined by multiple definitions of contents and applied paragraph style for each content.
I don’t know if this is possible. Just and idea.

The target is to compose a text frame composed by multiple paragraphs each with it’s particular Style.

Hagi

You’re close. I would do a repeat loop, cycle thru paragraphs. and apply styles and right after you inserted the text. Something like this (untested):

set everyParagraphs to {{textContent:"the text", textStyle:"Title"}, {textContent:"the second text", textStyle:"Running"}}

tell application "Adobe InDesign CS6"
	tell active document
		set frameRef to item 1 of selection
		repeat with currentPara in everyParagraphs
			tell insertion point -1 of frameRef
				set contents to textContent of currentPara
				set applied paragraph style to textStyle of currentPara
			end tell
		end repeat
	end tell
end tell

This is just a start of course, you’ll have to adapt this to your needs. Hope this helps!

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)