View Single Post
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 11:27 PM.. Reason: fixed code blocks