The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniGraffle > OmniGraffle General
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
AppleScript to quickly build a set of text objects Thread Tools Search this Thread Display Modes
Here's an AppleScript that will take a simple text object and create multiple text objects which represent all it's lines.

I use this to paste in a list of site map objects from (eg.) an email or a spreadsheet, and quickly generate separate text objects for me to then join up.

If I have a very long nested list I'll instead import into OmniOutliner, save as an outline, then open in OmniGraffle, create the outline, and copy/paste into my real document. As you can see, that path isn't worth it for a dozen lines or so.

Code:
tell application id "OGfl"
	tell front window
		set theSelection to the selection
		set theItem to item 1 of theSelection
		set theText to (text of theItem) as text
		set theSize to size of theItem
		set theHeight to item 2 of theSize
		set theOrigin to the origin of theItem
	end tell
	set theDown to (item 2 of theOrigin) + theHeight
	set theRight to item 1 of theOrigin
	set theLines to paragraphs of theText
	set numLines to length of theLines
	repeat with lineNo from 1 to numLines
		set theDown to theDown + 16
		set theOrigin to {theRight, theDown}
		set theLine to item lineNo of theLines
		tell canvas of front window
			make new shape at end of graphics with properties {draws stroke:false, fill:no fill, origin:theOrigin, vertical padding:0, autosizing:full, size:{180.0, 13.0}, text:{text:theLine, size:11}, side padding:1, draws shadow:false}
		end tell
	end repeat
end tell
 
One thing this script doesn't get right is that sometimes it creates the new text shapes on a different layer. This is annoying, and occasionally frustrating if that layer happens to be marked as read-only. Baffling too in that the pencil icon is on the right layer, but the new shapes appear on a different layer.

What do I change to specify that "make new shape" occurs on a specific layer?
 
You can tell a layer to make a shape:

Code:
tell canvas of front window
	tell layer 1
		make new shape at end of graphics with properties {draws stroke:false, fill:no fill, origin:theOrigin, vertical padding:0, autosizing:full, size:{180.0, 13.0}, text:{text:theLine, size:11}, side padding:1, draws shadow:false}
	end tell
end tell
(each layer has its own graphics collection)
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -8. The time now is 02:10 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.