• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

How to Change the Extension's UI from the Ruby Script?

Scheduled Pinned Locked Moved SketchUp Tutorials
sketchup
2 Posts 2 Posters 5.4k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    huajiet
    last edited by 11 Mar 2020, 03:25

    Dear Sketchucationers,

    Looking for a quick intro/tutorial into how to manipulate the UI aspect of .rb scripts. For example, how can I change where an extension appears on the menu bar? or how can I change the items that appear in the context-click menu? Some Ruby tips appreciated too!

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 11 Mar 2020, 12:02

      Look through my RB scripts and see how this is done in detail...

      for a simple menu item

      SUBMENU=UI.menu("Plugins").add_submenu("Haujiet") #Or other menu by name e.g. 'Tools'
      SUBMENU.add_item("Add..."){Sketchup.active_model.select_tool(Haujiet_Tool.new())}
      SUBMENU.add_item("Settings..."){Haujiet_Module;;settings()}
      

      for a command

      CMD1=UI;;Command.new("Tool_name"){Haujiet_Module;;some_module_action()}
      CMD1.tooltip="How_to_use_tool..."
      CMD1.status_bar_text="How_to_use_tool..."
      CMD1.small_icon=File.join(FOLDER_path, 'icon.png')
      CMD1.large_icon=File.join(FOLDER_path, 'icon.png')
      

      and for Toolbar

      TOOLBAR=UI;;Toolbar.new("Haujiet...")
      TOOLBAR.add_item(CMD1)
      TOOLBAR.restore if TOOLBAR.get_last_state.abs == 1 #TB_VISIBLE/NEVER
      

      for a context menu

      UI.add_context_menu_handler{|menu|
        sub = menu.add_submenu("Haujiet...")
        sub.add_item(CMD1)
        # perhaps with tests to see if it should show - e.g. the selection is a group?
      }
      

      See here...
      http://ruby.sketchup.com/UI/Command.html
      http://ruby.sketchup.com/UI/Toolbar.html

      TIG

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      1 / 1
      • First post
        1/2
        Last post
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement