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: saving canvases Thread Tools Search this Thread Display Modes
Hi All,

I'm trying to extend the 'autoexport' applescript, and wish to handle multiple-page/canvas drawings by saving each canvas as a separate image. I don't want to use the 'entire document' export area option as a) it exports full-page rt. just the objects, and b) it creates separate files in a new subdirectory (I wish to export file.graffle -> file.1.png, file.2.png, etc).

Sooo, I've tried:
Code:
tell application "OmniGraffle Professional"
	save canvas 1 of first item of documents in file ((desktop folder as string) & "ssh.png")
end tell
but that doesn't work:
Code:
OmniGraffle Professional got an error: NSReceiversCantHandleCommandScriptError
I guess you can only "save" (export) a document - so I guess I have to iterate over each canvas and save? How do I change the active canvas?


BTW, how come there's always one document returned by 'documents'? The following is with OG open, but no open docs:

Code:
tell application "OmniGraffle Professional"
	documents
end tell
-> {document "Basic.graffle" of application "OmniGraffle Professional"}

Thanks in advance,
Ben
 
Being able to save an individual canvas as you first tried is really something we ought to add...

For now, you'll have to iterate over the canvases via:

Code:
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 canvas of front window to canvas canvasNumber of theDocument
		save theDocument as "png" in (saveFolder & "ssh" & canvasNumber & ".png")
	end repeat
end tell
1. You have to ask for desktop from the Finder, otherwise you'll just get back the string "desktop" instead of the actual path.
2. The way you switch canvases is by setting the active canvas on the window.
3. You need to have the - as "png" - part on the save command, or else it'll think you want to save in the standard graffle format and any "."s are just part of the name.

And the reason why you always see at least one document is because the current stencil is also available as a document for scripting.
 
Thanks for the code, and the tips.

Quote:
3. You need to have the - as "png" - part on the save command, or else it'll think you want to save in the standard graffle format and any "."s are just part of the name.
In the 'autoexport' script you provided (and my thanks again, this has made my workflow much more efficient!), the code is:

Code:
  save theDoc in file target_path
I presume this is in fact relying on the 'current export settings' to be set to the appropriate type? But there doesn't seem to be a 'format' property to the current export settings.

With 'save as ...', is there a list of the strings associated with each format? (or just the standard png, svg, tiff, etc?)

BTW, should I have been able to find the above in any doc? (teach a man to fish :-)

Update: I've fiddled with the 'repeat with [each canvas]; set canvas of front window ...; save ...' to find that whilst this works well for unopened documents, it upsets any documents that are actually open in OG at the time of the auto-export. i.e. I'll be editing away, and all of a sudden the script kicks in and starts flipping my canvas pages... I guess the only solution is a 'save canvas' function?

Thanks,
Ben

Last edited by af3556; 2006-04-19 at 06:10 AM..
 
In experimenting with manipulating canvases, I've found the AS interface a little inconsistent.

I want to essentially do the following:

Code:
tell application "OmniGraffle Professional"
	set targetCanvas to ... (canvas to be manipulated)

	-- where were we?
	set theDocument to document of front window
	set oldCanvas to canvas of front window -- who's on first?
	
	-- do stuff
	set canvas of front window to canvas targetCanvas of theDocument
	display dialog "Done doing stuff"

	-- put things back to how we found them...
	set canvas of front window to canvas oldCanvas of theDocument
end tell
But this doesn't work, as 'set canvas ... to canvas N' expects N to be the index of the desired canvas in the canvas list, rather than the canvas object or even the canvas ID as returned by 'canvas of ...'.


Exposition:

I have the following canvases:
Code:
tell application "OmniGraffle Professional"
	canvas of document of front window
end tell
->
{canvas id 1 of document "ssh.graffle" of application "OmniGraffle Professional", 
canvas id 3 of document "ssh.graffle" of application "OmniGraffle Professional", 
canvas id 2 of document "ssh.graffle" of application "OmniGraffle Professional"}
Note the order: id's {1, 3, 2}

The third canvas is active (in front) (id 2).
Code:
tell application "OmniGraffle Professional"
	id of canvas of front window
end tell
-> 2
All good so far.

How to make canvas id 3 active? 'set canvas of front window to canvas' requires an index (into the list of canvases), not a canvas id.

[BTW: Is it correct there is no 'index of' operator in AS? (e.g. index of 5 in {3, 7, 8, 5, 2, 3}) If this is correct then the only option is to search (e.g. via a repeat loop) for the canvas list index corresponding to the desired canvas id.]

It would be useful to have the canvas 'set' and 'get' operations be consistent (i.e. either ID or index for both).

Rgds,
Ben

Last edited by af3556; 2006-04-25 at 10:27 PM.. Reason: fixed code blocks
 
You can refer to oldCanvas directly, you don't need to look it up by index again. Like this:

Code:
tell application "OmniGraffle Professional"
	-- where were we?
	set theDocument to document of front window
	set oldCanvas to canvas of front window -- who's on first?
	
	-- do stuff
	set targetCanvas to canvas 2 of theDocument
	set canvas of front window to targetCanvas
	display dialog "Done doing stuff"
	
	-- put things back to how we found them...
	set canvas of front window to oldCanvas
end tell
 
Code:
set oldCanvas to canvas of front window
...
set canvas of front window to oldCanvas
Makes sense, of course. (Can you tell I just don't grok applescript? :-)

Thanks.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get a list of selected canvases using applescript fikovnik OmniGraffle General 0 2013-01-09 07:25 AM
Canvases keep re-sizing themselves PRV OmniGraffle General 6 2012-07-25 04:38 PM
multiple master canvases, new canvases wynntemp OmniGraffle General 2 2009-02-23 01:44 PM
Turn layers on/off across all canvases fjordaan OmniGraffle General 3 2008-07-31 11:50 AM
How to set guides across multiple canvases sugarfreejones@gmail.com OmniGraffle General 0 2008-07-30 01:44 PM


All times are GMT -8. The time now is 09:04 PM.


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