Refresh Model Info Dialog in Ruby

Okay, I’m new to Ruby and am toying around with adding a toolbar. So far, I’m able to create my toolbar, add the buttons I want which trigger an event when clicked. That event contains code to change the values to what I’ve selected. What I am unable to figure out is how to refresh the Model Info dialog so it displays the changes I’ve just made.

For example, I created a button to toggle the units format to decimal. It works perfectly, except that the Model Info dialog does not reflect the change unless I click out of the Model Info Units page and then click back into the Model Info Units page.

Is there a way from Ruby to refresh the Model Info Units page after a change has been made?

Have you tried the UI::refresh_inspectors method ?

Seems to work for me.

“Administrative” note: I would like to ask you to edit your first post and put it - in my opinion - better category to: Developers: Ruby API



On topic: Dan already mentioned a good solution. It will refresh all of the inspectors “flashes the entire screen” a little. That wouldn’t be a big issue… :wink:

just thinking loudly…

Using:
UI#show_model_info-class_method

e.g.:

UI.show_model_info('Units')

…will refresh it too. But the big downside is that it opens the Model info window even if it hasn’t been opened yet.
Unfortunatlly I don’t know if there any method to check if the model info window is already opened or not…

BTW calling it with empty string (or string what does not exist in UIl#model_info_pages (Array<string>) will refresh it too, or open the Model info as last sown…

UI.show_model_info('')
UI.show_model_info('blabla')
1 Like

Thanks for the recommendation to change category - it has been done.

Also, the UI::refresh_inspectors works fine. Appreciate the input Dan and dezmo.

If I may trouble you with one last question. How can I toggle the selected color of the icons? I can obviously determine their value, but would like to know the current selection state based on the color of the icon.

Again, appreciate the insights - very helpful!

I guess you created the toolbar icon something like in example of:
UI/Command#large_icon-instance_method

Once you created the toolbar there is no chance to change the icon but you can “colorize” by graying it out if you do a validation process on the command associated to the toolbar icon.
UI/Commandl#set_validation_proc-instance_method

E.g :

module JStockCo
module Myunit_togle
  @@loaded = false unless defined?(@@loaded)
  
  unless @@loaded
    cmd1 = UI::Command.new("mm"){
      Sketchup.active_model.options["UnitsOptions"]["LengthUnit"] = 2
      UI::refresh_inspectors
    }
    cmd1.set_validation_proc{
      if Sketchup.active_model.options["UnitsOptions"]["LengthUnit"] == 2
        MF_GRAYED
      else
        MF_ENABLED
      end
    }
    cmd2 = UI::Command.new("feet"){
      Sketchup.active_model.options["UnitsOptions"]["LengthUnit"] = 1
      UI::refresh_inspectors
    }
    cmd2.set_validation_proc{
      if Sketchup.active_model.options["UnitsOptions"]["LengthUnit"] == 1
        MF_GRAYED
      else
        MF_ENABLED
      end
    }
    cmd3 = UI::Command.new("inch"){
      Sketchup.active_model.options["UnitsOptions"]["LengthUnit"] = 0
      UI::refresh_inspectors
    }
    cmd3.set_validation_proc{
      if Sketchup.active_model.options["UnitsOptions"]["LengthUnit"] == 0
        MF_GRAYED
      else
        MF_ENABLED
      end
    }
    
    cmd1.small_icon = "mmSmall.png"
    cmd1.large_icon = "mmLarge.png"
    cmd2.small_icon = "feetSmall.png"
    cmd2.large_icon = "feetLarge.png"
    cmd3.small_icon = "inchSmall.png"
    cmd3.large_icon = "inchLarge.png"
    cmd1.tooltip = "mm"
    cmd2.tooltip = "feet"
    cmd3.tooltip = "inch"
    mytoolbar= UI::Toolbar.new("JS Units")
    mytoolbar.add_item(cmd1)
    mytoolbar.add_item(cmd2)
    mytoolbar.add_item(cmd3)
    # etc....etc... 

    mytoolbar.restore
    @@loaded = true
  end

  ## your code here
  
end
end

Happy birthday!

Thanks!

I figured out about 90% of it this morning - thanks for taking me the rest of the way. I actually like the results of MF_CHECKED over MF_GRAYED better, but it’s all working perfectly now.

And thanks for the BD wishes!

2 Likes