Sorry for the sloppy subject line in my earlier question. Thanks, Kam, Matt for your very helpful replies. Kam, any idea how I would initialize the alloc'd shape to be e.g. a Circle of some size at some position? I generated the files with sdef & gen_bridge_metadata, found lots of useful things there. Is there something in these files that would lead me to: shape = OmniGraffleShape.alloc.init canvas.shapes.addObject shape ? I don't see either alloc or init, or addObject in the 2 files. Also, is there some reason why there is no corresponding "make ..." method in either file? Applescript gladly seems to call "make" (so does Ruby Appscript) on doc, canvas, or layer ... but I'm no Applescript guru :-( Thanks !!
Sophie, alloc.init is the same as new in Ruby and probably make in applescript. Basically, alloc allocate an object of a given type and initialize it. All instances of a class can be initiated using alloc.init. If you look at my previous post, I started working on an application that document the ScriptingBrige interfaces, here is a screenshot: https://img.skitch.com/20111115-dy4wrh9ppbybhxm4j4xn33ip9h.jpg
From what I'm seeing the code you pasted missed a way to fetch the "canvas" object. But "canvas" is an instance of Omnicanvas which has a #shapes method returning an array to which Kam adds the shape previously created.
I hope that helps. - Matt On Tue, Nov 15, 2011 at 4:43 PM, Sophie <itsme213@hotmail.com> wrote:
Sorry for the sloppy subject line in my earlier question.
Thanks, Kam, Matt for your very helpful replies.
Kam, any idea how I would initialize the alloc'd shape to be e.g. a Circle of some size at some position?
I generated the files with sdef & gen_bridge_metadata, found lots of useful things there. Is there something in these files that would lead me to:
shape = OmniGraffleShape.alloc.init canvas.shapes.addObject shape
? I don't see either alloc or init, or addObject in the 2 files.
Also, is there some reason why there is no corresponding "make ..." method in either file? Applescript gladly seems to call "make" (so does Ruby Appscript) on doc, canvas, or layer ... but I'm no Applescript guru :-(
Thanks !!
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Hi Sophie, Here is a little example, that I hope makes things more clear. graffle = SBApplication.applicationWithBundleIdentifier("com.omnigroup.OmniGrafflePro") win = graffle.windows.first canvas = win.canvas circle = OmniGraffleProfessionalShape.alloc.initWithProperties({:name=>"Circle", :origin=>[100.00, 100.00], :size=>[300, 300]}) canvas.shapes.addObject(circle) The example above uses the class name that should match what is in the header file that you generated. You can also use a slightly different method for getting the correct class: circle = graffle.classForScriptingClass("shape").alloc.initWithProperties({:name=>"Circle", :origin=>[100.00, 100.0], :size=>[300.0, 300.0]}) the -classForScriptingClass method takes the name of the class you would use in Applescript and then returns the class that the ScriptingBridge machinery expects. Just a slightly different approach and useful if you know the name of the class you would use in Applescript, but not the actual name used by ScriptingBridge. If you look in the header that you generated for OmniGraffle, you will see a bunch of @property declarations in each of the class definitions. The names of these properties you use as the keys in the initWithProperties method. Alternately you could also do: circle = OmniGraffleProfessionalShape.alloc.init canvas.shapes.addObject(circle) circle.setName("Circle") circle.setOrigin([100.0, 100.0]) circle.setSize([300.0, 300.0]) If you are going to set properties on an object, it must be added to a container first. Most of this is explained pretty well in the ScriptingBridge documentation, which is probably worth a look: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Scrip... hth kam P.S. the origin and size properties are actually defined as part of the OmniGraffleProfessionalGraphic class which OmniGraffleProfessionalShape inherits from. On Nov 15, 2011, at 11:43 AM, Sophie wrote:
Sorry for the sloppy subject line in my earlier question.
Thanks, Kam, Matt for your very helpful replies.
Kam, any idea how I would initialize the alloc'd shape to be e.g. a Circle of some size at some position?
I generated the files with sdef & gen_bridge_metadata, found lots of useful things there. Is there something in these files that would lead me to:
shape = OmniGraffleShape.alloc.init canvas.shapes.addObject shape
? I don't see either alloc or init, or addObject in the 2 files.
Also, is there some reason why there is no corresponding "make ..." method in either file? Applescript gladly seems to call "make" (so does Ruby Appscript) on doc, canvas, or layer ... but I'm no Applescript guru :-(
Thanks !!
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
This and many other great examples of "how to do FOO in MacRuby" lead me to wonder whether the wiki (or any wiki) is really being used to its fullest? Some real gems (no pun intended) have gone by, and it would be awesome for newcomers to have a place to go where they can explore a variety of "How can I make MacRuby do ..." examples and maybe even find links to sample projects or code snippets (like this one) that various folks have kindly donated. Searching mailing list archives is a pain, in other words, and information like that below really ought to be preserved for posterity. So.... If you're a reader of this list who would like to contribute to the overall health and success of the MacRuby community but don't feel comfortable or qualified to hack on the code base itself, this would be a GREAT contribution! - Jordan On Nov 15, 2011, at 3:11 PM, Kam Dahlin wrote:
Hi Sophie,
Here is a little example, that I hope makes things more clear.
graffle = SBApplication.applicationWithBundleIdentifier("com.omnigroup.OmniGrafflePro")
win = graffle.windows.first canvas = win.canvas
circle = OmniGraffleProfessionalShape.alloc.initWithProperties({:name=>"Circle", :origin=>[100.00, 100.00], :size=>[300, 300]}) canvas.shapes.addObject(circle)
The example above uses the class name that should match what is in the header file that you generated.
You can also use a slightly different method for getting the correct class:
circle = graffle.classForScriptingClass("shape").alloc.initWithProperties({:name=>"Circle", :origin=>[100.00, 100.0], :size=>[300.0, 300.0]})
the -classForScriptingClass method takes the name of the class you would use in Applescript and then returns the class that the ScriptingBridge machinery expects. Just a slightly different approach and useful if you know the name of the class you would use in Applescript, but not the actual name used by ScriptingBridge.
If you look in the header that you generated for OmniGraffle, you will see a bunch of @property declarations in each of the class definitions. The names of these properties you use as the keys in the initWithProperties method. Alternately you could also do:
circle = OmniGraffleProfessionalShape.alloc.init canvas.shapes.addObject(circle) circle.setName("Circle") circle.setOrigin([100.0, 100.0]) circle.setSize([300.0, 300.0])
If you are going to set properties on an object, it must be added to a container first.
Most of this is explained pretty well in the ScriptingBridge documentation, which is probably worth a look: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Scrip...
hth kam
P.S. the origin and size properties are actually defined as part of the OmniGraffleProfessionalGraphic class which OmniGraffleProfessionalShape inherits from.
On Nov 15, 2011, at 11:43 AM, Sophie wrote:
Sorry for the sloppy subject line in my earlier question.
Thanks, Kam, Matt for your very helpful replies.
Kam, any idea how I would initialize the alloc'd shape to be e.g. a Circle of some size at some position?
I generated the files with sdef & gen_bridge_metadata, found lots of useful things there. Is there something in these files that would lead me to:
shape = OmniGraffleShape.alloc.init canvas.shapes.addObject shape
? I don't see either alloc or init, or addObject in the 2 files.
Also, is there some reason why there is no corresponding "make ..." method in either file? Applescript gladly seems to call "make" (so does Ruby Appscript) on doc, canvas, or layer ... but I'm no Applescript guru :-(
Thanks !!
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
participants (4)
-
Jordan K. Hubbard
-
Kam Dahlin
-
Matt Aimonetti
-
Sophie