The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   AppleScript: Updating the text of a shape without affecting the formatting (http://forums.omnigroup.com/showthread.php?t=9335)

jschel 2008-08-12 03:05 AM

AppleScript: Updating the text of a shape without affecting the formatting
 
Hi!

I'm currently working on an AppleScript that takes text values from an excel sheet and puts these into a omnigraffle document. I'm running into a problem when setting the text to a new value. The formating of the original text is lost.

ex:
[CODE]
set text of current_graphic to "a new value"
[/CODE]

defaults the formating to 13pt Helvetica.

How do i update the value of a text without losing its formatting?

-- Update --
After some emailing with support and trial and error i've managed to find a solution. I'm putting it up here in case anyone else is stuck with this issue:

AppleScript:
[CODE]
tell application "OmniGraffle Professional 5"
set foo to first item of graphics of canvas of first document
copy properties of text of foo to myRecord
set class of myRecord to record
set myRecord to {text:"and yet another"} & myRecord
set text of foo to myRecord
end tell
[/CODE]

While this will actually work it's a bit of an unwieldy aproach:

When copying the properties of the text to a new record it is copied as a 'text' class (3). When setting the properties of a text a 'record' class is expected(6) so the class of the new record needs to be changed to record(4).
To update the text property of the record you need to concatenate the existing record with a record containing the new text(5).

This way you can update the copy with a new value.


All times are GMT -8. The time now is 12:11 AM.

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