How to display an info floating window


I would like to be able to display a floating window that shows key information about my script. Things like project name, values of some parameters, etc… My script generates different versions of the original Skethcup file in an hierarchy. The info displayed by the window would allow me to understand at a glance where I am in the hierarchy.

Can you please direct me to the correct way to do this? I guess I will have to use webDialog and Javascript, but I wanted to check first :smile:


Yes, a WebDialog would be fit for that task.

Though if you are new to WebDialogs you probably want to scan through these notes regarding quirks with Webdialogs:

1 Like

Sounds a lot like the Outliner window.

There is also a multi-line UI.messagebox(), but it’s modal.

OK Thanks. I managed to create my first WebDialog and create a basic table (This will contain my project info). Please consider that I am completely new to HTML. I have been reading quite a bit but I am still struggling to achieve what I need.

This is the ruby code

# sample.rb
require 'sketchup.rb' 
	"Project Info", true, "", 
400, 300, 100, 100, false )
wd.add_action_callback("create_table") do |js_wd, message|
	#UI::messagebox( 'I\'m Ruby. JavaScript said: "' + message + '"' )
	text = "Project"
	js_command = 'tableCreate("' + text + '")'
	puts message
#Show file		
wd.set_file( 'C:\\Filelocation\\sample.htm')

…and this is the sample.htm file

	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
			body {background-color:white}
			h1   {color:blue}
	<title> Project Information 	</title>
		<script type='text/javascript'>
			function tableCreate(text){
				var body = document.body,
				tbl  = document.createElement('table');
				//'200px'; = "1px solid black";
				for(var i = 0; i < 3; i++){
					var tr = tbl.insertRow();
					for(var j = 0; j < 3; j++){
						var td = tr.insertCell();
						td.appendChild(document.createTextNode(text + ' (' + i + ',' + j + ')')) = "1px solid black";
			function tableUpdate(tbl, text, i, j){
				var body = document.body;
				tbl.rows[i].cells[j].innerHTML = text;				

			function create_table( cb_name, msg ) {
				fake_url = 'skp:' + cb_name + '@' + msg
				window.location.href = fake_url
			create_table("create_table", "tbl" )

If I have understood correctly, I cannot execute a script without a callback. Is this right?

I have a couple of questions (actually a bit more, but 2 will suffice for now :slight_smile: )

  1. I don’t really understand how to execute the function tableUpdate without executing tableCreate again.
  2. How do I return the reference to tbl to my ruby script?

Thanks a lot

Btw, for simple UI need you can also try out SKUI: GitHub - thomthom/SKUI: Ruby wrapper of classes that maps to GUI controls in SketchUp's UI::WebDialogs
It wraps the webdialog controls in pure Ruby wrapper classes.

Another tip:
On PCs is needed to let you still work while the dialog is in front of the main dialog.
show_modal keeps it always in front but stops you working in SketchUp.
BUT on a MAC the ‘show’ dialog will move behind the SketchUp window when you click on something.
On a MAC you need to use show_modal to keep it in front BUT on a MAC you can still work in the SketchUp window…
Test for different OSs using something like this:

if (RUBY_PLATFORM.downcase =~ /mswin|mingw/) != nil ### PC
else #MAC

Then to set OS specific things:

if MAC

Awesome! Great work.

Thanks. It’s exactly what I need.


You didn’t mention whether your html was static or whether the info in the WebDialog would change after it was displayed.

If it is static, and if the info won’t change, there’s another method you can use, which is to use the set_html method of WebDialogs. You don’t need a separate file for the html. This concept can also be used (with some javascript) to replace the UI::messagebox.

# SketchUp set_html demo code
# html variable is a Ruby HERE doc
html = <<-'00HERE!!'
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
        <title>Project Information</title>
        <style type="text/css">
            body {background-color:white; font-size:1em;}
            h1   {color:blue;}
            table {border:1px solid black; border-collapse:collapse;}
            td    {border:1px solid black; padding:0.3em 0.5em 0.3em 0.5em;}

# below replaces placeholders inside of td elements
html.sub!(/_0_0/, "Rojj")
html.sub!(/_0_1/, "is")
html.sub!(/_0_2/, "Here")

html.sub!(/_1_0/, "Thom")
html.sub!(/_1_1/, "was")
html.sub!(/_1_2/, "There")

html.sub!(/_2_0/, "Greg")
html.sub!(/_2_1/, "might be")
html.sub!(/_2_2/, "here")

wd ="Project Info", true, "", 400, 300, 100, 100, false )