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 Today's Posts

 
Working with the Text of a Shape in OmniGraffle Thread Tools Search this Thread Display Modes
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,
 
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}}

Last edited by cwingrav; 2010-05-03 at 11:44 AM..
 
You can assign a nested property list to reset the text 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
[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 references further down this thread.

--

Last edited by RobTrew; 2012-02-09 at 02:21 PM..
 
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
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
 
Quote:
Originally Posted by cwingrav View Post
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
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 http://bit.ly/ce3E3O

--

Last edited by RobTrew; 2010-05-04 at 09:02 AM.. Reason: added link to discussion on the Apple Mailing lists
 
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.
 
Quote:
Originally Posted by cwingrav View Post
Thanks for the answer. Wish it were a happier one though... argh.
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
 
Quote:
Originally Posted by snarke View Post
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....
**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.
 
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
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}
 
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.



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
Your script fragment gives:



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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotating a shape in OmniGraffle ekin OmniGraffle General 4 2013-03-21 02:30 AM
When I click an shape why does it always think I want to edit the text? edgley OmniGraffle General 9 2012-04-24 02:20 PM
Shadow from text inside shape mlevin777 OmniGraffle General 4 2011-05-27 10:06 AM
Control shadow of Shape Text? Sophie OmniGraffle General 3 2010-05-06 02:52 PM
Text to shape conversion digimarkus OmniGraffle General 2 2009-10-14 01:26 PM


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


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