Finding a graphic using user data property
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 |
You're lucky
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?) |
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 [/QUOTE] 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[/QUOTE] |
All times are GMT -8. The time now is 01:15 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.