One of the interesting features of SketchUp's Ruby API is the UI::WebDialog class. Since WebDialog supports DHTML and JavaScripts, you can provide a rich, custom user experience for your SketchUp plugin users. You may be thinking, just another dialog box pretending to be a browser-lite, right? But there's more: with WebDialog you can call Ruby code from within the DHTML content of the dialog's document. No, this isn't some kind of listen-to-port-80-and-redirect trick. You define a block of execution in your Ruby code, assign it to the WebDialog object by name, and when the user selects the input element with that name the block is executed. Let's say you have an input element such as this:
<a href="skp:myAction@Hello">say hi!</a>Now, all you have to do is define a block of execution and assign it with the name "myAction."
dialog.add_action_callback("myAction") { |d, p| puts p } When the user clicks on the input element, it's the equivalent to
proc = Proc.new { |d, p| puts d} proc.call(dialog, "Hello") Simple and useful.

6 comments:
This is awesome! Thanks to this post I now have a much nicer dialog for my script :)
I noticed a couple things:
The examples in the docs are not accurate like the blog post (inconsistent action)
WebDialog is missing from: these docs
Are those docs not used anymore?
I also tried using set_file and it doesn't do the nice ruby interpretation.
And I have a slightly unrelated question, is latlong being worked on? it still doesn't work.
Thanks!
-Ian
Hi Ian,
The WebDialog is created using UI::WebDialog.new(params, .., ..)You won't find any WebDialog methods in the UI class you need to look in the WebDialog class WebDialog Class (http://download.sketchup.com/sketchuphelp/gsu6_ruby/Docs/Ruby-WebDialog.html)
Also, the set_file methods works but you need to put the file(html file) name first and then a absolute or relative path to that file example: mydialog.set_file("file.html", "/path/")
I'm not sure about the state of latlong, I'd hate to give you misinformation.
Hope this helps
Brad
Brad.
Thanks for the response! I see I didn't look hard enough at the docs :)
I did get the mydialog.set_file reading in a file, it was just that things like #{somevar} and skb:action@param weren't interpreted, they were simply rendered as text. I ended up just using mydialog.set_html since it wasn't that much, and that worked wonderfully!
Thanks again!
-Ian
Wonderful, I know such function exists, but only today i really had to use it. As other post mentioned, docs are little hard to understand about webdialog.
Thanks
runescape money
runescape gold
runescape money
runescape gold
buy runescape gold buy runescape money runescape items
runescape accounts
runescape gp
runescape money
runescape power leveling
runescape money
runescape gold
dofus kamas
cheap runescape money
cheap runescape gold
Guild Wars Gold
buy Guild Wars Gold
lotro gold
buy lotro gold
lotro gold
buy lotro gold
lotro gold
buy lotro gold
Hellgate Palladium
Hellgate London Palladium
Hellgate money
Tabula Rasa gold tabula rasa money
Tabula Rasa Credit
Tabula Rasa Credits
Hellgate gold
Hellgate London gold
wow power leveling
wow powerleveling
Warcraft PowerLeveling
Warcraft Power Leveling
World of Warcraft PowerLeveling World of Warcraft Power Leveling runescape power leveling
runescape powerleveling
eve isk
eve online isk
eve isk
eve online isk
tibia gold
Fiesta Silver
Fiesta Gold
Age of Conan Gold
buy Age of Conan Gold
aoc gold
呼吸机
无创呼吸机
家用呼吸机
呼吸机
家用呼吸机
美国呼吸机
篮球培训
篮球培训班
篮球夏令营
china tour
beijing tour
beijing travel
china tour
tibet tour
tibet travel
computer monitoring software
employee monitoring
runescape money
runescape gold
runescape money
runescape gold
buy runescape gold buy runescape money runescape items
runescape accounts
runescape gp
runescape money
runescape power leveling
runescape money
runescape gold
dofus kamas
cheap runescape money
cheap runescape gold
Guild Wars Gold
buy Guild Wars Gold
lotro gold
buy lotro gold
lotro gold
buy lotro gold
lotro gold
buy lotro gold
Hellgate Palladium
Hellgate London Palladium
Hellgate money
Tabula Rasa gold tabula rasa money
Tabula Rasa Credit
Tabula Rasa Credits
Hellgate gold
Hellgate London gold
wow power leveling
wow powerleveling
Warcraft PowerLeveling
Warcraft Power Leveling
World of Warcraft PowerLeveling World of Warcraft Power Leveling runescape power leveling
runescape powerleveling
eve isk
eve online isk
eve isk
eve online isk
tibia gold
Fiesta Silver
Fiesta Gold
Age of Conan Gold
buy Age of Conan Gold
aoc gold
呼吸机
无创呼吸机
家用呼吸机
呼吸机
家用呼吸机
美国呼吸机
篮球培训
篮球培训班
篮球夏令营
china tour
beijing tour
beijing travel
china tour
tibet tour
tibet travel
computer monitoring software
employee monitoring
Post a Comment