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

setting Text properties using Ruby appscript or RubyOSA Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
So here is some sample Ruby Appscript for OmniGraffle, for those who are interested. I did an application in AppleScript which take data from Numbers and builds a diagram in OmniGraffle. The problem was it was too slow to be useful. (I mean, I let it run over night and it was still chugging away in the morning.) So, I switched to Ruby and Appscript. I'm running into some new problems, that I can't seem to sort out. If anybody can help that would be great. I will post additional questions on this thread as well as success.

The one thing I'm trying to get right is how to set the size of the text and the alignment of the text. Below is my code...

begin; require 'rubygems'; rescue LoadError; end

require "appscript"
include Appscript

# assumes the document specified is open and the canvas is named as specified
_DocumentName = "Sample Scripting Diagram.graffle"
_CanvasName = "Ruby Test Canvas"

--This is the AppleScript of the two shapes...
tell application "OmniGraffle Professional"
	tell canvas of front window
		make new shape at end of graphics with properties {name: "Circle", textSize: {0.800000, 0.700000}, text placement: top, fill: no fill, textPosition: {0.100000, 0.150000}, origin: {75.000000, 194.857147}, autosizing: vertically only, size: {250.000000, 34.285713}, text: {text: "This Shape #1", font: "Helvetica-Bold", text: "This Shape #1"}, draws shadow: false}
		make new shape at end of graphics with properties {text placement: top, fill: no fill, origin: {100.000000, 400.000000}, autosizing: vertically only, size: {200.000000, 24.000000}, text: {text: "This Shape #2", text: "This Shape #2"}, draws shadow: false}
	end tell
end tell

  puts "Working with canvas: #{_CanvasName} of document #{_DocumentName}"
  #puts app('OmniGraffle Professional 5') # => prints out the names of all the documents (looks like it includes templates, too)
  workingCanvas = app('OmniGraffle Professional 5').documents[_DocumentName].canvases[_CanvasName]  # gets the canvas we want to work with.
  #Create a new shape without specifying propterties
  shapeOne = => :shape)
  # Now I go down the list of properties and try to set them
  shapeOne.origin.set([100 , 200])
  shapeOne.size.set([200 , 75])
  shapeOne.text_placement.set(:top) # I've had some incosistant results with using 'top' in single quotes. However, the :top seems to work always
  shapeOne.text.set("This Shape #1")
	shapeOne.fill.set(:no_fill) # I tried putting 'no fill' instead of :no_fill and it doesn't seem to work. The result is fill: 0
  #thisNewShape.text.alignment.set(:center) # This doesn't work and I can't seem to figure out how to set the alignment of the text
  #thisNewShape.text.size.set([10]) # This doesn't work and I can't seem to figure out how to set the size of the text

  shapeTwo = => :shape , :with_properties => { :origin => [100 ,  400] , :size => [200 , 75], :text_placement => :top , :text => "This Shape #2" , :fill => :no_fill ,:draws_stroke => true ,  :autosizing => :vertically_only , :name => 'Rectangle', :draws_shadow => false})

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting AppleScript variable to text of a cell Patrick J OmniOutliner 3 for Mac 2 2011-12-03 03:31 PM
Text Editing in Preferences not setting Jolt21 OmniGraffle General 1 2011-04-08 09:21 AM
Default text align setting enfact OmniGraffle General 3 2010-09-14 06:26 AM
Export Properties:Notes as HTML Roll Over Text? jeffreykennedy OmniGraffle General 6 2009-10-26 07:40 AM
RubyOSA newtonapple OmniFocus Extras 2 2007-10-16 08:08 PM

All times are GMT -8. The time now is 01:00 AM.

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