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

 
Working with the Text of a Shape in OmniGraffle Thread Tools Search this Thread Display Modes
It has always been possible to create styled text, but a couple of problems with changing the color etc of a part of a text are:
  1. Automatic type conversion of text in Applescript,
  2. buggy screen updating in OmniGraffle.

Some work-arounds are:
  1. Indirection (use of references rather than simple variable assignments),
  2. micro zoom adjustments of the OG screen.

You can change the color of the Nth word by applying that change to a reference (bypassing automatic conversion of the text to a string variable), but you won't see the result on the OG screen until you force a rewrite by making a small change to the zoom level:

Code:
tell application id "OGfl"
	tell front window
		tell its canvas
			set oShape to item 1 of shapes
			
			set refText to a reference to text of oShape
			set color of word 3 of refText to {0, 0, 65535}
		end tell
		
		set zoom to zoom * 0.99
	end tell
end tell
 
PS for existing formatting which does not correspond to predictable word or character boundaries, it may be useful to inspect/change properties of attribute runs.

Code:
tell application id "OGfl"
	tell front window
		tell its canvas
			set oShape to item 1 of shapes
			
			set refText to a reference to text of oShape
			set color of attribute run 2 of refText to {0, 0, 65535}
		end tell
		
		set zoom to zoom * 0.99
	end tell
end tell
PPS a peculiar quirk of the screen-updating bug: if you subseqently revert to the original zoom level, you will sometimes find that it still displays the previous state of formatting ...

(A save and reopen will fix it).

--

Last edited by RobTrew; 2012-02-03 at 02:50 AM..
 
Thus, to search and replace text formatting properties:

Code:
-- Search and replace formatting properties
tell application id "OGfl"
	tell front window
		tell its canvas
			set oShape to item 1 of shapes
			
			set refText to a reference to text of oShape
			tell refText
				-- change anything redder to green
				repeat with oRun in attribute runs
					set {lngR, lngG, lngB} to color of oRun
					if (lngR > lngG and lngR > lngB) then set color of oRun to {0, 65535, 0}
				end repeat
			end tell
		end tell
		
		set zoom to zoom * 0.99
		refText
	end tell
end tell
and to simply list them:
Code:
-- List formatting properties
tell application id "OGfl"
	tell front window
		tell its canvas
			set oShape to item 1 of shapes
			
			tell text of oShape -- still an uncoerced reference
				set lstProps to properties of attribute runs
			end tell
		end tell
	end tell
end tell
--

Last edited by RobTrew; 2012-02-03 at 04:32 AM..
 
Generally, if you need to script text format changes to OmniGraffle, it is probably quite important that you are aware of a pair of 'model lag' bugs, a Scylla and a Charybdis, which can either mean that the screen is misrepresenting the state which your data will be in when you save it, or can mean that the Applescript interface will be misrepresenting that state.

It turns out that the OmniGraffle screen can even deceive us as to the contents of the text in our documents ...

--

Last edited by RobTrew; 2012-02-09 at 04:42 AM..
 
Quote:
Originally Posted by RobTrew View Post
Thus, to search and replace text formatting properties:

Code:
-- Search and replace formatting properties
tell application id "OGfl"
	tell front window
		tell its canvas
			set oShape to item 1 of shapes
			
			set refText to a reference to text of oShape
			tell refText
				-- change anything redder to green
				repeat with oRun in attribute runs
					set {lngR, lngG, lngB} to color of oRun
					if (lngR > lngG and lngR > lngB) then set color of oRun to {0, 65535, 0}
				end repeat
			end tell
		end tell
		
		set zoom to zoom * 0.99
		refText
	end tell
end tell
and to simply list them:
Code:
-- List formatting properties
tell application id "OGfl"
	tell front window
		tell its canvas
			set oShape to item 1 of shapes
			
			tell text of oShape -- still an uncoerced reference
				set lstProps to properties of attribute runs
			end tell
		end tell
	end tell
end tell
--
Hi Rob,

I ran into this very thing today.

I came up with the following solution: not as flexible as yours - you'd need to set a property for each text-style you want to use - but it works in my situation, and it's not very much code.

(I didn't read the whole thread - apologies if someone earlier offered this.)

-- create a list of all desired text properties EXCEPT for its text property:

property _labelTextProperties: {size:_fontSize, color:{1, 1, 1}}

-- to create an object with a caption using the style above:

set _label to make new shape at end of graphics with properties {text: _labelTextProperties & {text: _labelText}, [other object properties]}

-- to change the text of (the text of) the object:

set text of _label to _labelTextProperties & {text: _newLabelText}
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


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:34 AM.


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