How to display Window/Component Options from Ruby?

I’m extending a Ruby script I wrote for personal use some years ago. It adds a menu to insert a selected Dynamic Component, using

  if (myComponent !=0)
    Sketchup.active_model.place_component myComponent, false

How can I make sure either that the Dynamic Component Options window is open already, or open it if it isn’t?

I can get a ‘handle’ on it using (from the Ruby API) method

myMenu ="Window/Component Options")

but I can’t see a method either to display it, or to check if it is already displayed.

I’ve looked in the API docs for Methods called Show or Display, but they don’t seem to apply to Window objects.

And this Window doesn’t appear in the list of Inspectors, Pages, or Toolbars so I can’t use UI.show_inspector or UI.show_preferences. I could just display the Dynamic Component toolbar, but I really want to open the Component Options window.

Is what I want to do possible? If so, how, if anyone can point me in the right direction to work it out, or show me an example.

PS. I experimented in the Ruby Console after getting myMenu.

both give errors, and when i list the methods, I don’t see one that would do what I want (scroll sideways to see them all):

> myMenu.methods
[:add_item, :set_validation_proc, :add_separator, :add_submenu, :to_json, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]

.display and .inspect both just return the object ID.

PPS: AHA!. A broader Google search showed up an old Sketchucation Forum post that I hadn’t found before:

The key line is:


Now who would have thought of that, reading the API docs?

And thanks in advance to @DanRathbun, who provided the original answer.

It is a UI::WebDialog instance object. (The entire Dynamic Components extension is a Ruby extension.)

The toolbar itself is a UI::Toolbar instance object (not a native toolbar.) And although there is a iterator method to get ahold of the UI::Command objects attached to the toolbars, there is no getter method to get the command’s proc objects.

  • EDIT (2022-08-16): Access to command proc objects was added in the 2022.0 release.
    Now extensions that need this reference to the proc (like toolbar editors, etc.) no longer need to (nor should) modify the UI::Command class constructor to “steal” the reference.

No actually that does not work. That just gets a handle on the “Window” menu itself. (Ie, we have asked for path string arguments to get at nested submenu(s), but it has yet to be implemented.)

Because it is undocumented. Basically it is an OEM Ruby extension.

Knowing how to get there, involves “inside information” from the original author (who is now no longer with the OEM,) and good use of Ruby’s introspection methods.

1 Like

Dan, double thanks for the clarity of explanation. And for the depth of your own inside knowledge, and your willingness to share it here.