Problem getting started with WebDialog to set ruby Tool parameters

I’m trying to develop my first WebDialog.

I used Martin Rinehart’s sample code for the WebDialog HTML page and the Ruby script that calls it, and it works to pass static messages back and forth.

But as soon as I put the [ClickMe!] button inside <form></form> tags, it stops working and nothing is communicated back to the Ruby console.

I haven’t been able to find a simple example of a WebDialog that uses a form to set parameters for a Tool in Ruby, and wonder where I could find one? Or do I not need to use a form, but just ‘raw’ <input> tags?

And I thought I remembered that ThomThom had written some wrapper code to simplify the development of WebDialogs. I have just found a reference to his SKUI code, on GitHub, but it seems very old (refers to SU 6 and says it is still a ‘work in progress’). I’ve also found a reference on this forum that says ‘avoid the skp: protocol’, which is what Martin Rinehart uses. There’s also a tutorial on engineeringtheworld, but again, it is old (2010), and doesn’t use an html form. And tt_su’s Wiki “Web Dialogs, the Lost Manual” is mostly a list of ‘gotchas’ - important, but I haven’t got that far yet.

I’ve tried looking at Jim Foltz’s MoveIt tool, which I saw recommended as a model, but it is large and complex - several hundred lines of code - so it’s difficult to see the essence of it.

Feeling stuck at the moment, and would welcome some pointers to get to the next stage of developing my first WebDialog. Maybe I’m just being dense in not finding recent good examples - is there a simple (preferably written, not video) tutorial that I just haven’t found that someone could point me to?

Thanks for any help you can give to get me started. Quite willing to work at it, and I have some but not extensive experience in all three of JavaScript, HTML, and Ruby, so I’m not starting from square zero. Just not yet getting to square one!

I’ve designed the web HTML form I want to use, and can get Ruby to open it ready for the user to fill in the form, but I just can’t see how to pass the data back to Ruby at the moment.

And I want Ruby to populate the form with the most recently used values, if that’s possible too.

Well, I’ve got a bit further. By putting action = "button_click()" in the <form> tag, I can now get the submit button to work, and send the sample fixed text to Ruby.

But since the button_click() code WAS being activated before I did that (or at least, it triggered a JS ‘alert’ that I added to it), I’m not clear why I need to use the form action instead. Is it something to do with asynchronous messaging on the Mac, so it was being sent before Ruby was ready to receive it?

Now to figure out how to include values from the form input fields in what is sent back to Ruby, and how to insert the previous values from Ruby as the preset values in the form when it is next opened.

[LATER] Well, I THOUGHT I had got the submit button to work - but I see it was still outside the <form></form> tags, not inside as I thought. So that problem is NOT solved. So I’m still stuck.

Not that old. But yet, still relevant. The mentions of SU6 is how far back the compatibility with SU is.

Do you have a small minimum example of what you are working with? Without seeing some code it’s a little bit difficult to know exactly what we’re dealing with here.

Yes, I can post two sample files I’m trying to get working, but not for an hour or two - busy for a while until then.

And sorry I misunderstood about SKUI - I’ve read a bit more since first posting here, and see that if I can get my head round it, it should do what I want.

I really only need one small step up from the Ruby InputBox - seven or eight text boxes, and a drop down list with half a dozen fixed choices.

And I want to fill the boxes/make the first selection by filling in the current values of the parameters for the tool from Ruby.

Here are my two sample files, zipped - sample.rb to load the WebDialog sample.html file and set up a callback function. They are only slightly modified from Martin Rinehart’s example. (1.8 KB)

I have them in Plugins/sample, hence the pathname in Sketchup.find_support_file( …) . I haven’t made an installable Extension (yet), so you may have to change the path, or create a /sample folder in Plugins and extract the files into it.

And I just load the sample.rb file from the Ruby console.

Will mock up later the appearance of a form i’d like to use as the basis for customisation.

i want the result to run on both Mac (asynchronous JS/Ruby communication) and Windows (synchronous).

Here’s a very simple form which I’d like to use as a basis for laying out the parameters of the tool I’m working on. (933 Bytes)

How do I get Ruby to fill in preset values using (I guess) something in each <input ...> tag value = "insertRubyValue"?

And how can I pass back the input values as (again, I guess) a JSON string to Ruby from the form when the user clicks the [Submit] button?

This seems such a simple requirement from which to elaborate, but I can’t find any example that I understand of how to do this.

And I’ve now looked again at SKUI. How do I adapt example.rb to generate such a form? Again, if there is guide to how to do this, I’m sorry but I can’t find it on the GitHub pages. And looking at the code in the file examples.rb i can’t see where to start simplifying it down to a few text boxes, a drop down, and (maybe) one checkbox - which I didn’t mention before because it has only just occurred to me that it could be useful.

And maybe add (perhaps just in HTML?) a (?) Help button, to pop up a small HTML window with explanation of the various options and values to set in the form.

I’m really sorry if I appear dense. I seem not to be ‘getting’ the WebDialog at all, in terms of how to produce what seems such a simple result.

I really DO want to get this to work, and if I do, would happily spend some time trying to produce a HowTo for the benefit of others, if there isn’t one already. And if there IS, why can’t I find it?

I posted some code for a very similar dialog HERE

you don’t need to use forms and submit buttons as you have control over both ruby and javascript…

I’ll have a look at yours when I get a moment…


Thank you. I’ll look at your code as soon as I can - possibly not tonight though.

Ah, I had read that thread, but didn’t really understand the code, nor quite see the parallel to what I’m trying to do. Not sure that I do even now, on re-reading it! But I’ll study it further tomorrow, and see if I can adapt it.

That’s a good common scenario. I filed an issue internally for us to provide such an example. We are in the process of producing new ones.

An example of this kind would be GREAT - it’s exactly what I want, but I simply cannot find anywhere I’ve looked