Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download
Centering/Positioning a WebDialog at Load
-
This is a How-To demonstrating one way of positioning a WebDialog at the time it is first shown.
The ruby file:
w=UI;;WebDialog.new f = File.dirname(__FILE__) + "/w.html" w.set_file( f ) w.add_action_callback("move") { |d, a| xy, wh = a.split(";") x, y = xy.split(",") x = x.to_i y = y.to_i w, h = wh.split(",") w = w.to_i h = h.to_i d.set_position((x - w)/2, (y - h)/2) } w.showThe html file:
<html> <head> <script> function move_to_center() { window.location = "skp;move@" + screen.width + "," + screen.height + ";" + document.body.offsetWidth + "," + document.body.offsetHeight; } </script> </head> <body onLoad="move_to_center()"> Hi </body> </html>Another way is to execute a script in the dialog's show method:
w.show { w.execute_script("move_to_center()") }You then eliminate the need for the "onLoad" in the html body tag.
-
Hey Jim. Is there a question here, or are you posting how to do it?
-
Heh, it's supposed to be a how-to in reponse to this question.
Advertisement