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)
-   -   Working with the Text of a Shape in OmniGraffle (http://forums.omnigroup.com/showthread.php?t=11161)

Joe.Hocker 2009-01-26 01:06 PM

Working with the Text of a Shape in OmniGraffle
 
I'm have trouble understanding how to work with text of an object.
I have made a sample and then copied as AppleScript.
I would like to break down the properties so that I can work with them.
I'd like to set the text and maybe even change the text of an existing shape.

Here is what the copied AppleScript looks like:

tell application "OmniGraffle Professional"
tell canvas of front window
make new shape at end of graphics with properties {name: "RoundRect", textSize: {0.800000, 1.000000}, user data: {myFirst: "1", myThird: "3", myforth: "4", mySecond: "2"}, fill: no fill, textPosition: {0.100000, 0.000000}, origin: {109.000000, 177.794006}, vertical padding: 0, size: {231.242004, 26.227800}, text: {text: "test", text: "test", alignment: center}, side padding: 0, draws shadow: false}
end tell
end tell

Below is the the modified AppleScript. As you can see I have commented out the text property because it didn't work.
I can only seem to set the text property when I create the shape.
I would really like to know how to work with the text of a shape.


tell application "OmniGraffle Professional 5"
tell canvas of front window
make new shape
set lastGraphicID to (get id of result)
tell graphic id lastGraphicID
make new user data item with properties {name:"myFirst", value:"1"}
make new user data item with properties {name:"mySecond", value:"2"}
make new user data item with properties {name:"myThird", value:"3"}
make new user data item with properties {name:"myforth", value:"4"}
set name to "RoundRect"
set textSize to {0.8, 1.0}
set fill to no fill
set textPosition to {0.1, 0.0}
set origin to {15.0, 204.397003}
set vertical padding to 0
set size to {231.242004, 26.2278}
--set text to {text: "test", text: "test", alignment: center}
set side padding to 0
set draws shadow to false
end tell
end tell
end tell


Thanks,

cwingrav 2010-05-03 10:42 AM

I would too. This requires some developer help because I can't figure out how to set text without destroying existing text properties (such as color, size, font, etc). I can't even figure out how to get existing color, size and font from text.


in case this helps some (g is a shape):

[CODE]set text of g to { text: "My new text", size: 8, font: "arial", alignment: center, color:{65535,65535,65535}}[/CODE]

RobTrew 2010-05-03 02:22 PM

You can assign a nested property list to reset the [B][COLOR="Blue"]text[/COLOR][/B] property of an existing shape, and apply different formats to different parts of the string ...

[CODE]tell application "OmniGraffle Professional 5"
tell canvas of front window
set text of front shape to {{text:"text in two "}, {text:"fonts", font:"HoeflerText-Regular", size:24}}
end tell
end tell[/CODE]

[UPDATE] To read the formatting properties of different attribute runs, you need to avoid coercing the text property to a string variable. Examples of using [I]references[/I] further down this thread.

[COLOR="White"]--[/COLOR]

cwingrav 2010-05-04 04:49 AM

How do I get it to change just the color of the text without replacing the entire text and its properties? Something like:
[CODE]tell application "OmniGraffle Professional 5"
tell canvas of front window
set color of properties of front shape to {0, 0, 65535}
end tell
end tell[/CODE]

Or, how do I get the color of the existing text? Where are the properties for text held as I can't find them in the existing DOM. How would I say the following:
[CODE]tell application "OmniGraffle Professional 5"
tell canvas of front window
set p to color of properties of front shape
-- or
set p to color of second text of properties of front shape
end tell
end tell[/CODE]

RobTrew 2010-05-04 07:52 AM

[QUOTE=cwingrav;76749]How do I get it to change just the color of the text without replacing the entire text and its properties?

Or, how do I get the color of the existing text? Where are the properties for text held as I can't find them in the existing DOM[/QUOTE]

Both impossible, I believe.

My understanding is that Apple Events don't speak the language of "Rich Text", so there is no obvious way for Omni developers (or any other developers) to enable you to fetch rich text properties through applescript ...

There is some recent technical chat between developers grappling with these issues at [URL="http://bit.ly/ce3E3O"]http://bit.ly/ce3E3O[/URL]

[COLOR="White"]--[/COLOR]

cwingrav 2010-05-04 08:38 AM

Ah, so it stores this information in a rich text format that is not accessible to us scripts. Any chance a future version of OmniGraffle will just use regular text and store the text attributes as entries in the DOM? This would be quite nice for us scripter end users.

BTW, this post, had I read it earlier, would have saved me hours over the several months I have looked for this answer.

Thanks for the answer. Wish it were a happier one though... argh.

snarke 2010-05-12 12:22 PM

[QUOTE=cwingrav;76757]Thanks for the answer. Wish it were a happier one though... argh.[/QUOTE]

I hate to disagree with the previous posters, but I have no trouble creating a box with (say) green text in it. I believe the following code should be equivalent to what you originally posted....

[CODE]tell application "OmniGraffle 5"
tell canvas of front window
set lastGraphicID to id of (make new shape at end of graphics with properties {name:"RoundRect", fill:no fill, draws shadow:false, size:{231.242004, 26.2278}, vertical padding:0, autosizing:full, origin:{15.0, 204.397003}, textSize:{0.8, 1.0}, textPosition:{0.1, 0.0}, rotation:0, text:{text:"test", font:"Helvetica", size:30, alignment:center, color:{0, 65535, 0}}, draws stroke:true, side padding:0})
tell graphic id lastGraphicID
make new user data item with properties {name:"myFirst", value:"1"}
make new user data item with properties {name:"mySecond", value:"2"}
make new user data item with properties {name:"myThird", value:"3"}
make new user data item with properties {name:"myforth", value:"4"}
end tell
end tell
end tell

[/CODE]

cwingrav 2010-05-12 12:36 PM

[QUOTE=snarke;77096]I hate to disagree with the previous posters, but I have no trouble creating a box with (say) green text in it. I believe the following code should be equivalent to what you originally posted.... [/QUOTE]

**snip**

Creating from scratch is not the problem. There is existing code for that. The problem is querying a graphic for its current properties which the above poster says isn't possible, a limitation of Applescript.

Thanks for the sample code though as someone else will probably find it useful.

ericscheid 2012-02-02 02:49 PM

You can get the styling properties of the text of a graphic with this applescript:

[CODE]
tell application "OmniGraffle Professional 5"
tell canvas of front window
set p to properties of text of shape 1
p
end tell
end tell[/CODE]

you will get something like this
{superscript:missing value, underlined:false, color:{0, 0, 0}, font:"Tahoma Bold", size:12.0, text:"some text", class:text, alignment:center, baseline offset:missing value}

whpalmer4 2012-02-02 03:58 PM

Well, you can get styling properties that apply to the whole thing, yes. However, if you make some different styling to part of the text, your technique doesn't work.

[URL=http://imageshack.us/photo/my-images/440/screenshot20120202at450.png/][IMG]http://img440.imageshack.us/img440/2546/screenshot20120202at450.png[/IMG][/URL]

Copy As Applescript gives:
[code]
tell application "OmniGraffle Professional"
tell canvas of front window
make new shape at end of graphics with properties {fill: no fill, draws shadow: false, size: {131.000000, 23.000000}, side padding: 0, autosizing: full, origin: {99.000000, 180.500000}, text: {{text: "This is a bit of ", text: "This is a bit of ", size: 11}, {text: "colored", text: "colored", size: 11, color: {1.000000, 0.000000, 0.000000}}, {text: " text.", text: " text.", size: 11}}, draws stroke: false}
end tell
end tell

[/code]

Your script fragment gives:

[URL=http://imageshack.us/photo/my-images/716/screenshot20120202at452.png/][IMG]http://img716.imageshack.us/img716/4011/screenshot20120202at452.png[/IMG][/URL]

I believe that shows the problem RobTrew is referring to above.


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

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