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: set multiple shape properties in 1 call? Thread Tools Search this Thread Display Modes
Apologies for re-post, I could not edit the title of the earlier post.

I am using Applescript to set the properties of some Omnigraffle shapes. I am using Python/appscript, but would appreciate any pointers in plain Applescript as well (or anything else).

When I get the properties of a shape, Omnigraffle returns a dictionary of all key-value pairs (color, text, stroke, locked, etc.). When I create a new shape I can similarly send in a bunch of properties as a dictionary e.g. (in Python/appscript):

doc.make(new=k.label,
at=line.labels.end,
with_properties={k.text: 'foo', k.draws_stroke = True})

Is there a way to update a bunch of properties of an existing shape with a single call, passing in a dict of properties? If so, any restrictions on which properties can be set this way?

e.g. When I tried
shape.properties.set({k.locked: True}) -- it worked.

But when I tried:
shape.properties.set({k.text: 'foo'}) -- it did nothing.

Thanks
 
You can assign a sub-dictionary of properties:

Code:
tell application id "OGfl"
	set lstSeln to selection of front window
	set oShape to item 1 of lstSeln
	tell canvas of front window
		--tell oShape to set {thickness, draws shadow} to {"Adjusted", 3, false}
		set properties of oShape to {thickness:4, draws shadow:true}
		set text of oShape to "Sample"
		properties of oShape
	end tell
end tell
text however, does seem to be a recalcitrant property, and there are generally some screen refresh issues with setting text formatting through applescript - there seems to be a lag between the model seen by applescript and the image seen by the user. A scripted zoom can sometimes show an updated image, but reverting to the old zoom will still show the pre-script image.

--

Last edited by RobTrew; 2012-11-12 at 12:34 AM..
 
or, within the scope of the object, assign a list of values to a list of keys.

Code:
tell application id "OGfl"
	set lstSeln to selection of front window
	set oShape to item 1 of lstSeln
	tell canvas of front window
		tell oShape to set {thickness, draws shadow} to {3, false}
		--set properties of oShape to {thickness:4, draws shadow:true}
		--set text of oShape to "Sample"
		--properties of oShape
	end tell
end tell
--

Last edited by RobTrew; 2012-11-12 at 08:33 AM..
 
Thanks, Rob!

Separately, is there actually a way to explicitly disable & re-enable screen refreshes through a script?
 
Quote:
Originally Posted by Sophie View Post
is there actually a way to explicitly disable & re-enable screen refreshes through a script?
All I can immediately think of is toggling the visible property of the layer(s) which you are writing to.
 
Ah, that will work, thanks!
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applescript: which shape properties can be set via a dictionary? Sophie OmniGraffle General 4 2012-11-23 09:17 AM
Best way to add multiple color (swatches) to a shape? Sophie OmniGraffle General 2 2012-11-19 09:41 AM
Set a bunch of shape properties in one call? Sophie OmniGraffle General 0 2012-11-07 10:28 PM
Using AppleScript to set the Script field of a shape MiBo OmniGraffle General 2 2011-07-27 11:21 AM
Protect shape properties mattydj OmniGraffle Extras 1 2009-10-22 04:43 PM


All times are GMT -8. The time now is 05:57 PM.


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