Need some help for writing a simple API to download models from web

One problem is that your JS function has no parameter. Within the function you are using the var buttonId (which is undefined,) but as said previously it’s the skp file name you should send back to Ruby.

The other issue is that you should be using the JS sketchup object that the newer UI::HtmlDialog class defines for you.

The old skp: location protocol was for the deprecated UI::WebDialog class.

So the function should look like:

    function buttonClicked(skp_file) {
      sketchup.button_clicked(skp_file);
    }

But you have an additional Ruby-side error in the naming of your Ruby callback. The names must match between the JS and Ruby but yours do not. The Ruby-side callback name should be "button_clicked" not "buttonClicked". It does not matter whether using the skp: protocol or the newer sketchup object, the callback name used to fire the Ruby side callback must be correct, or yes nothing will seem to happen.

Programming is about getting all the nitty details correct. Otherwise things will not happen or act as you wish.


This statement should not be needed inside an extension. Besides you would want the console open before loading any plugins to see any errors.

SketchUp versions from 2021.1 now remember if the console is open and will reopen it next session. So just manually open it, and leave it open when you close SketchUp. It should reopen in the next session before extension load.


Regarding the Ruby … you did not follow the instructions I gave.

  • Especially including the extend self statement so methods can call each other within your submodule without extra qualification.
  • If you want the size and position of your HTML dialog to be remembered correctly and restored automatically, then you must use a unique preferences key as shown.
  • Again your GUI object creation should be within a conditional block so it’s loaded only once during development. (As you wrote it, you’ll need to close and reopen SketchUp after each edit.)
  • Most important is that the main command proc has all the dialog code within it.
    • GUI command objects can not be redefined later. This is why I told you that the command code should actually be defined in a method, and the command proc only call that method.
    • The download() method does not go within the command proc, not within the other method. They each are defined at the same level. (They are sibling methods. The command method will can the download method when it needs to.)

Also, if using the API’s load_from_url method, your code need not load the open-uri library.

In addition, you don’t really need to require "sketchup.rb" as SketchUp loads this file before ANY extensions are processed. (It could be used if you want to load API stubs into an IDE later on when you are more comfy with coding.)

Lastly, the dialog reference needs to be persistent so that it does not get garbage collected. Use a @dialog variable instead of a dialog local variable.


Listen, I have arthritis in my hands and I’m really done with explaining this any further in print.

So there is a load of Ruby Resources to learn from. It will take time. More if your new to coding.