The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   How to create key-value pairs when creating a shape (http://forums.omnigroup.com/showthread.php?t=8202)

ianpiper 2008-06-16 10:43 AM

How to create key-value pairs when creating a shape
 
I have an AppleScript that creates a shape with a variety of properties. I have noticed that Omnigraffle 5 has the ability to create key-value pairs to store additional user-defined information, and I would like to do this programmatically (using AppleScript). But I cannot figure out the syntax. Can anyone help me?

Here is how I am currently creating my shapes:
"
on makeShape(aTitle)
tell application "OmniGraffle Professional 5"
tell canvas of front window
return make new shape at end of graphics with properties {text:aTitle, vertical padding:5, autosizing:full, side padding:10, magnets:{{0.5, 0}, {-0.5, 0}, {0, 0.5}, {0, -0.5}}, origin:{(x of canvasSize) / 2.0, (y of canvasSize) / 2.0}}
end tell
end tell
end makeShape
"
I would want to add things like type="node" or author="ian" and various other terms.

Thanks,


Ian.
--

Joel 2008-06-16 12:39 PM

The following should work:

{user data: {foo: "bar"},

Put that in the properties in your script and you should be good to go.

ianpiper 2008-06-17 07:31 AM

[QUOTE=Joel;38170]The following should work:

{user data: {foo: "bar"},

Put that in the properties in your script and you should be good to go.[/QUOTE]

Thanks Joel.

I wasn't sure about exactly where you meant I should put the braces, but I tried this and it didn't seem to have an effect (the blue text is what I have added: I am passing a string in as the id in this case, and want that to be the value for a key called "termId").

I would really like to have a bit more control over the shapes and layout as I create them - is there somewhere I can read the documentation for how to call things like Orthogonal line types, fill colours for shapes, drop shadows, layout types and so on?

AppleScript snippet:
return make new shape at end of graphics with properties {text:aTitle, url:aUrl, [COLOR="RoyalBlue"]user data:{termId:aId}[/COLOR], vertical padding:5, autosizing:full, side padding:10, magnets:{{0.5, 0}, {-0.5, 0}, {0, 0.5}, {0, -0.5}}, origin:{(x of canvasSize) / 2.0, (y of canvasSize) / 2.0}}


Ian.
--

ianpiper 2008-06-17 07:53 AM

Actually, it does work...
 
[QUOTE=ianpiper;38198]Thanks Joel.

I wasn't sure about exactly where you meant I should put the braces, but I tried this and it didn't seem to have an effect (the blue text is what I have added: I am passing a string in as the id in this case, and want that to be the value for a key called "termId").

Ian.
--[/QUOTE]

Joel,

<blush>I just checked it again and your suggested approach does work</blush>

It would still be nice if there were some documentation that I could look at for this. If the API is documented for any language somewhere I would be happy to work out the relevant calls for AppleScript. Is there such a beast?

Thanks again for your help,


Ian.
--

Joel 2008-06-17 09:51 AM

The OmniGraffle AppleScript Dictionary should have all of this documented (I think), however one of the far easier ways to get at this stuff is to create it in Graffle, then copy it as AppleScript from the Edit Menu --> Copy As submenu.

Cheers,

dghpts 2008-06-22 11:11 AM

Joel,
Once I attach the data to a shape using the Key Data Fields, is there a way to get it out of the drawing?
I'm using OGP5 to annotate floorplans for wire locations and types.
I built a Stencil with my symbols for each type of equipment and put the same Key Data fields in each shape, so when I drop a symbol on the floorplan I can input wire type, number and location information.
Would be great if I could create a table on a page that would pull out the data fields and show them!
I'll settle for an export to CSV, or TXT files though!

Joel 2008-06-22 11:23 AM

You may want to take a look at the .graffle file format itself (uncompressed). It's an XML property list, and you may be able to post-process the document if you're so inclined.

We do have a number of feature requests to have that data export to other formats, as an FYI.

dghpts 2008-06-22 11:30 AM

Joel! You're here!
Thanx for that info!

Is there a way to copy the key data fields from one shape to another?
Sort of like painting withe the properties brush?

Joel 2008-06-22 11:42 AM

There isn't, however that does sound like a very good idea.

dghpts 2009-02-06 12:38 PM

Joel.
I'm baaaack! Hey, was working on another system design and ran across the data pairs question again, did a search and found my own post, sucks getting old, you forget things.

I was wondering if there was a way have one of the key data pairs (or more) show up on the symbol itself. Sort of like the variables being used to add dates and file names ad such to drawing pages.

Any idea if this is possible? Would be great for marking up drawings, drop a part symbol on the drawing fill in the data and have the part number and wire number appear on the symbol in the drawing.

Does that make sense??

Joel 2009-02-06 02:51 PM

I believe there is a way to do this, however it's outside of my brain at the moment, I'll have to check with engineering about it.

jelaryma 2009-06-11 11:24 AM

[QUOTE=Joel;54845]I believe there is a way to do this, however it's outside of my brain at the moment, I'll have to check with engineering about it.[/QUOTE]

I was looking for exactly this functionality. I'd like to create a template/shape/stencil that will pull key/value pairs from the objects and place the values on the shape. A simple example is an org chart:
[CENTER]
[FONT="Arial Black"][B]<<title>>[/B][/FONT]
[FONT="Arial"]<<name>>[/FONT][/CENTER]

Might be displayed as

[CENTER] [FONT="Arial Black"][B]Chief Executive Officer[/B][/FONT]
[FONT="Arial"]Steve Jobs[/FONT][/CENTER]

Please let me know if this is possible...

whpalmer4 2010-02-06 06:16 PM

It is possible. In your stencil, you would have text fields such as

<%userdata title%>
<%userdata name%>

and you would use the Properties: Note inspector to add key/data pairs for title and name.

trouble clef 2011-08-12 11:27 AM

[QUOTE=dghpts;38564]Joel! You're here!
Thanx for that info!

Is there a way to copy the key data fields from one shape to another?
Sort of like painting withe the properties brush?[/QUOTE]

Is it not possible to add key - data pairs to an existing shape using AppleScript? Trying to do this myself.

If anyone has used MailTags the latest version does much the same thing. Of course the evolution of this would be to make the data and keys openly accessible as I think I'm right in saying that they aren't indexed by Spotlight.

whpalmer4 2011-08-12 12:16 PM

I've posted a couple of scripts that set key data pairs for existing shapes using Applescript. See my posts in

[url]http://forums.omnigroup.com/showthread.php?t=18864[/url]

and

[url]http://forums.omnigroup.com/showthread.php?t=17457[/url]

for sample code.

trouble clef 2011-08-12 12:27 PM

Thanks - good starting point.


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

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