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

 
Finding a graphic using user data property Thread Tools Search this Thread Display Modes
I could really use an example of querying for a shape based on the user data property of a shape.
Below are two examples, the later one is what I'm trying to use, but I don't know how to structure the query properly. The first query will show the user data the I'm trying to query on for the second statement.

get the user data of every graphic whose size is equal to {textwidth, textHeight}

get every graphic whose user data contains {name:"ObjectType", value:"App Type Text"}
:confused:

The log result looks like:

get user data of every graphic of canvas id 1 of document "Untitled 15" whose size = {190, 12}
{{|ObjectType|:"App Type Text"}, {|ObjectType|:"App Type Text"}, {|ObjectType|:"App Name Text"}, {|ObjectType|:"App Name Text"}}

get every graphic of canvas id 1 of document "Untitled 15" whose user data contains {name:"ObjectType", value:"App Type Text"}
{}
 
So, I've made some progress. But this is more of a work around....
I am now able to test for a name/value pair using an if statement.
But I'm still trying to get a graphic whose user data matches a specific name/value pair.

Here is how I'm able to use the user data in a 'if' statement...

set thisUserData to get the user data of the last graphic
if (|ObjectType| of thisUserData is equal to "Application Shape") then
log "Test True"
else
log "Test false"
end if
 
I can't even get the user data from the selection:

tell application "OmniGraffle Professional 5"
tell window 1 to get the user data of the selection
end tell

just gives this error:
Canít make user data of selection of window 1 into type reference.

If I just just ask for the selection:
tell application "OmniGraffle Professional 5"
tell window 1 to get the selection
end tell

I get back the expected graphic reference:
{graphic id 3845 of canvas id 9 of document "fotoFlag XL3.graffle" of application "OmniGraffle Professional 5"}

Methinks something is broken.

(I ran into this while trying to make a couple of simple scripts to copy and paste the user data from/to selected objects. Oughta be easy, right?)

Last edited by RobLewis; 2009-03-26 at 10:42 AM..
 
I totally understand your frustration. I pulled out what little hair I had left, trying to work with user data.
Just when I got the script to work with some sample data, I did a real test with a fair amount of data and performance was in the 'days' rather than minutes which I expected.
As a result all this code I'm sharing is obsolete, as I've converted to ruby and rb-appscript.

Example of making adding user data to a shape (grouped shapes in this case)
Quote:
set groupedAppShapes to assemble listOfGraphicsToGroup
tell groupedAppShapes
make new user data item with properties {name:"ObjectType", value:"Application Shape"}
end tell
Example of getting the user data from a graphic and inspecting that data. Note that this is just the opening part of a very long repeat loop, so you will seen some blocks are not ended or closed as didn't paste the entire block of code.
Quote:
-- get a graphic to work with...
repeat with clientAppGraphic in (get every graphic)
-- set a reference to that user data of the graphic
-- Yes this makes for longer code, but makes it easier to work with, in my opinion.
set clientAppGraphicUserData to the user data of clientAppGraphic
-- I couldn't figure out how to do any fancy 'where / whos' user data contains logic, so I use a simple 'if' condition to test for what I want...
if clientAppGraphicUserData contains {|ObjectType|:"Application Shape"} then
log "this is a application shape"
-- Now that I've found the graphic with the user data I was looking for, I set some variables using additional user data keys
set thisClientAppName to get |appName| of clientAppGraphicUserData
set thisRedundacnyRole to get |redundancyRole| of clientAppGraphicUserData
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Feature request: %variable% to show user data? ericscheid OmniGraffle General 1 2012-02-04 04:31 PM
AppleScript to query the user data key/value pairs apl OmniGraffle General 2 2012-01-14 01:05 AM
Applescript: user data item of canvas cyleigh OmniGraffle Extras 1 2011-05-04 08:59 PM
Leveraging custom/user data fink08 OmniGraffle General 1 2009-11-12 07:08 AM
Sharing OF data across user accounts beelers OmniFocus 1 for Mac 0 2007-11-24 04:51 PM


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


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