Illustrator - create text with line breaks

Hello,

I’m putting the finishing touches on a chart-creation script I am using at work. I’ve gotten past all the roadblocks except one. I would like to insert text with line breaks, but Illustrator seems to ignore the line breaks. Here’s some simplified code that gets to the point:

tell application "Adobe Illustrator"
	
	set thisText to "Hello
Forum"
	
	set t_text to make new text frame in document 1 with properties {contents:thisText}
	
end tell

This will create a text box that says “HelloForum” (no line breaks).

Anyone know what I can try? I’m clueless.

Thanks,
Dave

Dave:

Just as a quick reply…

set thisText to “Hello” & return & “Forum”

This doesn’t address formatting though. Look under the Paragraph options in the Text section of the AI dictionary for justification,etc. if you need it.

Hope this helps.

Jim Neumann
BLUEFROG

I can’t test this, but if I had to guess.

get "Hello
Forum"

get ASCII number (character 6 of result)
--> 10

This string is using Line Feeds; It’s possible that Illustrator is expecting Carriage Returns.

Try something like this:

tell application "Adobe Illustrator"
	set thisText to "Hello, Forum!

Does this work?"

	set ASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {(ASCII character 13)}
	set thisText to (paragraphs of thisText) as text
	set AppleScript's text item delimiters to ASTID

	set t_text to make new text frame in document 1 with properties {contents:thisText}
end tell

Dave,

The reason your result comes out “HelloForum” is because there is no space between the o and F for your input. If you want Hello and Forum to be on separate lines then follow BlueFrogs suggestion.

Here is some more info on text formatting:

tell application "Illustrator CS"
	activate
	
	set docref to make new document with properties {height:864, width:864}
	set thisDoc to current document
	make new spot in thisDoc with properties {name:"myBlue", color type:{spot color}, color:{cyan:100, magenta:80, yellow:30, black:5}}
	make new character style in thisDoc with properties {name:"style1"}
	set the size of character style "style1" of thisDoc to 8
	tell thisDoc
		set the fill color of character style "style1" of thisDoc to {class:spot color info, tint:100, spot:spot "myBlue"}
	end tell
	set the text font of character style "style1" of thisDoc to text font "Helvetica"
	make new text frame in thisDoc with properties {name:"text1", position:{100, 700}, contents:"Hello Forum"}
	apply character style character style "style1" of thisDoc to text range of text frame "text1" of thisDoc
	
end tell

Hope this helps.

Thank you all for the suggestions. Both of the solutions work as expected, and both can be good depending on use. Bluefrog’s suggestion is the most simple, and will work well when I can define the text within the script. If the text is coming from elsewhere and I don’t know if it contains line breaks or not, Bruce’s suggestion is a good choice.

PreTech, your formatting examples will serve as a good reference in the future. Thank you for contributing!