Add items to a list

Hello,

In the following sample, I would simply like to list the class of each entity. I think, my code to add the list item is incorrect and am wondering if someone can help.

dialog = UI::HtmlDialog.new(
{
:dialog_title => “Dialog Example”,
:preferences_key => “com.sample.plugin”,
:scrollable => true,
:resizable => true,
:width => 600,
:height => 400,
:left => 100,
:top => 100,
:min_width => 50,
:min_height => 50,
:max_width =>1000,
:max_height => 1000,
:style => UI::HtmlDialog::STYLE_DIALOG
})

html= ’
<!DOCTYPE html>
<html>
<head><title>My First Test</title></head>
<script type="text/javascript">
function test(){
sketchup.say(“Hello World”, “value 2”);
}

function test1(){
sketchup.printclass();
}

</script>
<body>
<b id="id">Hello world!</b>
<br />
<b id="test"> My Test </b>

<p>Click to test </p>
<p><input type="button" onclick=test1() value="Do Something" /></p>

<div id="test2">
</div>

</body>
</html> '

dialog.set_html(html)
dialog.show

dialog.add_action_callback(“say”) { |action_context, param1, param2|
text= “JavaScript said #{param1} and #{param2}”
UI.messagebox(text, MB_YESNO)
}

dialog.add_action_callback(“printclass”){

js_command = "document.getElementById('test2').innerHTML = '<ul id=ti>' + '</ul>'"
dialog.execute_script(js_command)
Sketchup.active_model.entities.each do |e|
js_command = "document.getElementById('ti').innerHTML+=  '<li>' + e.class.to_s + '</li>'"
dialog.execute_script(js_command)

end

}

Yogesh

HtmlDialog2.rb (1.3 KB)

Hi @yogesh

The main probelm is in this line:

js_command = "document.getElementById('ti').innerHTML+= '<li>' + e.class.to_s + '</li>'"

It needs to read:

js_command = "document.getElementById('ti').innerHTML+= '<li> #{e.class.to_s} </li>';"

Thank you, Jim!

PS- The “;” in the suggested code was giving an error so I had to remove the “;” to make it work.

You are welcome.

Here is a version with more typical structure for a single-file extension.

HtmlDialog2.rb (2.5 KB)

@jim_foltz, Once again thank you!