The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Applescript: set multiple shape properties in 1 call? (http://forums.omnigroup.com/showthread.php?t=26869)

Sophie 2012-11-11 09:00 PM

Applescript: set multiple shape properties in 1 call?
 
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 [I]existing[/I] 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

RobTrew 2012-11-11 11:22 PM

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[/CODE]

[I]text[/I] 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.

[COLOR="White"]--[/COLOR]

RobTrew 2012-11-11 11:35 PM

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[/CODE]

[COLOR="White"]--[/COLOR]

Sophie 2012-11-12 06:58 PM

Thanks, Rob!

Separately, is there actually a way to explicitly disable & re-enable screen refreshes through a script?

RobTrew 2012-11-17 03:28 PM

[QUOTE=Sophie;117234]is there actually a way to explicitly disable & re-enable screen refreshes through a script?[/QUOTE]

All I can immediately think of is toggling the [I]visible[/I] property of the layer(s) which you are writing to.

Sophie 2012-11-18 06:30 AM

Ah, that will work, thanks!


All times are GMT -8. The time now is 10:22 PM.

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