The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   AppleScript to quickly build a set of text objects (http://forums.omnigroup.com/showthread.php?t=29593)

ericscheid 2013-05-15 08:52 PM

AppleScript to quickly build a set of text objects
 
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
[/CODE]

ericscheid 2013-05-28 05:56 PM

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?

RobTrew 2013-05-29 03:05 AM

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

[/CODE]

(each layer has its own [I]graphics[/I] collection)


All times are GMT -8. The time now is 06:20 PM.

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