The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   AppleScripting Omni Apps (http://forums.omnigroup.com/forumdisplay.php?f=46)
-   -   Getting objects by "name" in Graffle (http://forums.omnigroup.com/showthread.php?t=14869)

timwilson 2009-12-30 06:31 PM

Getting objects by "name" in Graffle
 
I'm doing a little project with OmniGraffle, and I've gotten to the point that I think some AppleScript would be just the thing to make my life easier. (I've had "Learn AppleScript" on my Someday/Maybe list for a while now.)

I'm making a map of my school district and plan to use small squares to mark the locations of our elementary, junior high and high schools. Each of those three groups will have a different color, and the school graphics reside in three separate layers corresponding to elementary, jr. high, and high school. I've created some user data for each square graphic with a key "name" and value set to the abbreviation we use for that school (e.g., "mgsh").

Let's say I wanted to create an AppleScript that would look in the current document for a graphic element with user data: {name: "mgsh"} and set its fill color to blue.

Can I access that graphic element by name directly, or do I need to loop through all the objects in a given layer and look for it sequentially?

Any pointers would be greatly appreciated.

-Tim
(Proud OmniFan)

RobTrew 2010-03-05 11:00 PM

[QUOTE=timwilson;71121]Let's say I wanted to create an AppleScript that would look in the current document for a graphic element with user data: {name: "mgsh"} and set its fill color to blue.
[/QUOTE]

I haven't managed to query on the contents of the user data record, but you can query on the contents of the notes field.

If you place your identifier string in the the note of the graphic, you can retrieve the graphic(s) with notes containing that string:

[CODE]tell application "OmniGraffle Professional 5"
tell first canvas of first document

set lstShapes to shapes where notes = "mgsh"
if length of lstShapes > 0 then
set oShape to first item of lstShapes
-- set properties of oShape here

end if

end tell
end tell
[/CODE]

If you need to reserve the notes for other purposes, then iteration is probably the only route, but you can restrict the list of shapes through which you have to iterate by querying for those which do actually have user data.

[CODE]set lstShapes to shapes where user data is not missing value[/CODE]

RobLewis 2010-04-20 12:14 PM

Have you tried using the "tag" property?
Statements like this work for me:

set the_minor_fiducial to the first graphic whose tag is "minor"

It's not documented, but the tag property is just a special case of user data. It's a user data item with the name "_tag".


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

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