Help with WebDialogs
-
Hi,
I'm trying to follow the techniques outlined in the link below to interact between ruby and a web dialog
http://sketchupapi.blogspot.com/2008/02/sharing-data-between-sketchup-ruby-and.htmlI've got the Javascript to Ruby callbacks working just fine but am running into some weirdness going the other way. My code is below. Whats happening is that as is, the javascript doesnt execute. If I uncomment the messagebox line, then it does. Are there any known quirks to be aware of? Or is the messagebox line doing something that is required and can be accomplished in some other way?
I'm new to ruby and appreciate the help.
Thanks,
Joshdef LaunchGenericEditor
create a new web dialog
editor = UI::WebDialog.new("Generic Editor", false, "Generic Editor", 275, 100, 50, 50, true)
load the editor html and show the web dialog
html_path = File.dirname(File.expand_path(FILE))
html_path << "/GenericEditor.html"
editor.set_file(html_path)editor.show
strCommand = "addRowTest(5)"
#UI.messagebox strCommand
editor.execute_script(strCommand)
end -
You need to wait for the HTML to load.
I use a callback from the JS in the WebDialog to SketchUp when the HTML DOM has loaded. When the DOM has loaded you can start using wedialog.execute_script.
For more reading on WebDialogs: http://forums.sketchucation.com/viewtopic.php?f=180&t=23445&p=324694
-
Josh.. ONLY class and module identifiers are capitalized camel-case. Methods are lowercase with underscore separated words.
And you need to keep the 'handle' to the dialog outside the method. (or the dialog will go out of scope when the method call ends.) I usually have the dialog setup method return the handle as the last statement.
I'll use a instance var or a module var to hold the handle.
module Josh module WebEditor @@editor = nil class << self def launch_generic_editor() # setup code here return editor end #def end # proxy class # further down if not @@editor @@editor = launch_generic_editor() end @@editor.show() end # WebEditor end # Josh
-
Thanks guys! Calling back to ruby from the onload did the trick. I'm obviously new to ruby and appreciate all the pointers.
Thanks again for the help
Josh -
@joshb said:
I'm obviously new to ruby and appreciate all the pointers.
Pay attention to the "Sticky" threads at the top of the forum. (They have the "S" in them.)
This will get you going:
Ruby Newbie's Guide to Getting Started
Advertisement