Adding OmniGraffle diagrams to Word documents

OmniGraffle Script Menu

I recently bought OmniGraffle Professional to make some diagrams for a Word document. OmniGraffle is a great program that lets me easily create nice looking graphics.

I was happily cutting and pasting diagrams into my Word X document. Then I decided to test the document on Windows XP with Word 2003, just to see how it looked. I was expecting a font that wasn’t optimum or maybe something else small. Much to my suprise, all the pictures were gone. There was a message “QuicktimeTM and a TIFF (LZW) decompressor are needed to see this picture.”

Huh? I have Quicktime installed… That pesky Unisys patent expired… WTF? Grrr. OK I’ll blame Microsoft.

Lots of Googling later, I found some solutions.

Copy As Vector PICT seemed like a great idea. In OmniGraffle: Edit -> Copy As -> Vector PICT. Then paste into Word. Unfortunately this make the text in my diagrams look like really bad. It worked well for simple test diagrams I created, but not for the real ones. This wasn’t going to work, I bought OmniGraffle to make pretty diagrams.

The suggestion that worked best was exporting as PNG in OmniGraffle and then in Word: Insert -> Picture -> From File.

Unfortunately this was a tedious process. Select a Canvas, Select All, Export to PNG. Repeat. OmniGraffle will export a complete Document to PNG, but it padded a bunch of whitespace around the document.

This is what AppleScript is for right? (I don’t know AppleScript so I’m going to learn it better before I complain that I don’t like it.) After my own attempts at writing this script failed the OmniGraffle forums provided a solution. There were more complex solutions, but I wanted something simple that would add a new export function.

I modified the script to name the PNG using the Canvas name. I added this to the OmniGraffle Scripts Folder. In OmniGraffle: Script Menu -> Open Scripts Folder -> Open OmniGraffle Pro Scripts Folder. Now I have a new “Export as multiple PNGs” menu option. The script menu must be enabled for this to work.

(*
based on script from http://forums.omnigroup.com/showthread.php?t=146#post697
*)
tell application "Finder"
	set saveFolder to desktop as string
end tell

tell application "OmniGraffle Professional"
	set theDocument to front document
	set canvasCount to count of canvases of theDocument
	
	repeat with canvasNumber from 1 to canvasCount
		-- yuck applescript is clunky.  Is there a better way to get the canvas name?
		set canvasName to name of canvas canvasNumber of theDocument
		
		set canvas of front window to canvas canvasNumber of theDocument
		save theDocument as "png" in (saveFolder & canvasName & ".png")
	end repeat
end tell

The new “Export as multiple PNGs” just saves a bunch of PNG images to the desktop. This makes inserting the image into Word document easy because the Finder has a Desktop shortcut on the Sidebar. I have a bunch of ideas about how this could be improved, but it works good enough so I’m sure it will just stay as-is.

Advertisements
Posted in applescript, mac, omnigraffle, word
4 comments on “Adding OmniGraffle diagrams to Word documents
  1. PMcM says:

    Your link to my site roughly tripled my traffic. Good reminder to actually get around to putting something more topical on it!

    Also, in my experience Applescript only gets more frustrating the more you get into it. The only way I’ve found to make it at all bearable is to use a LOT of functions, rather than long blocks of code.

  2. SwimRat007 says:

    i adapted it a bit, however the new .png file created retains the orional document name

    tell application “Finder”
    set saveFolder to desktop as string
    end tell

    tell application “OmniGraffle Professional”
    set theDocument to front document
    set canvasCount to count of canvases of theDocument

    repeat with canvasNumber from 1 to canvasCount

    set canvasName to name of canvas canvasNumber of theDocument

    set canvas of front window to canvas canvasNumber of theDocument
    set docName to name of first document
    set finalName to (do shell script “echo ” & docName & “| sed -e ‘s/\\(.*\\)\\.graffle/\\1/'”) & “.png”
    save theDocument as “png” in (saveFolder & finalName)
    end repeat
    end tell

  3. skicAcign says:

    Подскажите шооблончег под WordPress 2.6.2, чтобы был похож на ваш donc.wordpress.com.

    Заранее благодарю)

  4. sarah samson says:

    Very helpful and save me a lot of time! Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: