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 > Developer > AppleScripting Omni Apps
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Getting objects by "name" in Graffle Thread Tools Search this Thread Display Modes
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)
 
Quote:
Originally Posted by timwilson View Post
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.
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
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

Last edited by RobTrew; 2010-03-05 at 11:46 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".
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
German localization problems, WebDAV iCal export due: "fällig" vs. "Fälligkeitsdatum" FatalError OmniFocus 1 for Mac 5 2011-04-08 06:32 AM
How to "hide" lines behind objects? santra OmniGraffle General 0 2009-09-03 07:36 AM
Why are graffle "read-only"? JamesSchriver OmniGraffle General 0 2007-01-25 08:06 AM


All times are GMT -8. The time now is 11:31 PM.


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