Nonetheless, this week I wrote three simple Applescripts for the OmniGraffle vector drawing application out of necessity. The first two export either all of groups or graphics of a OmniGraffle document as a particular format. This is useful if you create a large number of graphics that you want to export, or as I often do, create a large number of groups of graphics that each comprise an icon. There is no 'batch' export in OmniGraffle because they almost certainly figured that someone would just use Applescript to do it.
The third is even simpler; it just imports a comma-delimited list of value pairs as the endpoints of line segments. That is, it draws x-y coordinates as a single connected graphic. The syntax for doing this can be learned by drawing something and then ->Edit->Copy As->Applescript....a very neat feature.
Just cut and paste the scripts below into the Script Editor and save them under ~/Library/Scripts/Applications/OmniGraffle (or OmniGraffle Pro)
OminGraffle export all groups
------------------------------------------------------------
--Copyright 2009, Sunny Fugate
--Creative Commons Attribution-Share Alike 3.0
--http://creativecommons.org/licenses/by-sa/3.0/us/
--
tell application "OmniGraffle Professional 5"
--Setup export options
set current export settings's area type to selected graphics
set current export settings's draws background to false
set current export settings's export scale to 1
set current export settings's include border to false
set current export settings's resolution to 2.0
--Retrieve the desired output export path
set myFolder to POSIX path of (choose folder)
--Get the desired output format
set outputTypeList to {"PDF", "TIFF", "PNG", "GIF", "JPEG", "EPS", "SVG", "PICT", "BMP"}
choose from list outputTypeList with prompt "Choose export format"
set exportformat to result as text
--Get the desired file prefix
set prefixDialog to display dialog "Enter a desired output file prefix or leave blank" default answer ""
set filePrefix to the text returned of prefixDialog
--Get the current document for later use
set currentDocument to document of front window
--Get a list of the canvases
set theCanvases to every canvas of currentDocument
--Use a counter for unique naming
set counter to 0
--Loop over each canvas
repeat with aCanvas in theCanvases
--Make sure that the current canvas is displayed
--(export of currently selected only works in the displayed window
set canvas of front window to aCanvas
--get a list of groups for this canvas
set theGroups to every group of aCanvas
get theGroups
--loop over each group
repeat with aGroup in theGroups
get aGroup
--Set the selection of the window and save / export
set selection of front window to {aGroup}
save currentDocument as exportformat in POSIX file (myFolder & filePrefix & (counter))
set counter to counter + 1
end repeat
end repeat
end tell
OmniGraffle export all graphics
--------------------------------------------
--Copyright 2009, Sunny Fugate
--Creative Commons Attribution-Share Alike 3.0
--http://creativecommons.org/licenses/by-sa/3.0/us/
--
tell application "OmniGraffle Professional 5"
--Setup export options
set current export settings's area type to selected graphics
set current export settings's draws background to false
set current export settings's export scale to 1
set current export settings's include border to false
set current export settings's resolution to 2.0
--Retrieve the desired output export path
set myFolder to POSIX path of (choose folder)
--Get the desired output format
set outputTypeList to {"PDF", "TIFF", "PNG", "GIF", "JPEG", "EPS", "SVG", "PICT", "BMP"}
choose from list outputTypeList with prompt "Choose export format"
set exportformat to result as text
--Get the desired file prefix
set prefixDialog to display dialog "Enter a desired output file prefix or leave blank" default answer ""
set filePrefix to the text returned of prefixDialog
--Get the current document for later use
set currentDocument to document of front window
--Get a list of the canvases
set theCanvases to every canvas of currentDocument
--Use a counter for unique naming
set counter to 0
--Loop over each canvas
repeat with aCanvas in theCanvases
--Make sure that the current canvas is displayed
--(export of currently selected only works in the displayed window
set canvas of front window to aCanvas
--get a list of groups for this canvas
set theGroups to every graphic of aCanvas
get theGroups
--loop over each group/graphic
repeat with aGroup in theGroups
get aGroup
--Set the selection of the window and save / export
set selection of front window to {aGroup}
save currentDocument as exportformat in POSIX file (myFolder & filePrefix & (counter))
set counter to counter + 1
end repeat
end repeat
end tell
OmniGraffle draw line from clipboard
--------------------------------------------
--Copyright 2009, Sunny Fugate
--Creative Commons Attribution-Share Alike 3.0
--http://creativecommons.org/licenses/by-sa/3.0/us/
--
--Expect values to be comma delimited x,y with linebreak between each value
set theData to the clipboard
set AppleScript's text item delimiters to (ASCII character 13)
set valueList to every text item of theData
--set numberString to "{"
set numberList to {}
set AppleScript's text item delimiters to {","}
repeat with value in text items of valueList
--stupid extra repeat which never repeats to emulate a repeat 'next/continue'
repeat while true
try
set x to item 1 of text items of value as number
set y to item 2 of text items of value as number
on error theError number errorNum
exit repeat
end try
set numberList to numberList & {{x, y}}
exit repeat
end repeat
end repeat
tell application "OmniGraffle Professional 5"
tell canvas of front window
make new line at end of graphics with properties {point list:numberList}
end tell
end tell
6 comments:
Very useful and helpful... thank you!
Looking for just this - many thanks.
Great script, especially love the Export Groups one. We improved it by added the canvast name to the exported filenames, so its easier to keep the exports apart, for instance while building a prototype with them. Source can be found at https://github.com/bramchi/OmnigraffleScripts
Hello, Thanks for these scripts! Do you know if is it possible to export graphics coordinates? It could be useful in case of replacing exported graphics in their correct position (relative to the background image).
Thanks again!
Hi Pierre,
I'm sure it is possible, but you would need to make some assumptions about the objects (or export lots of additional metadata). If the objects are simply composed of points and lines, then this should be trivial. If, however you are using more complex objects, then there would be a ton of additional metadata required. In the end, for export of objects you would probably be better served by looking into export using an existing format such as SVG, which is text-based XML underneath. So, exporting to SVG and then manipulating the XML data to suite your needs is probably a better approach. Cheers -- Sunny
Greeat blog
Post a Comment