Module: UI
- Defined in:
- lib/sketchup-api-stubs/stubs/ui.rb
Overview
The UI module contains a number of methods for creating simple UI elements from a SketchUp Ruby script.
Defined Under Namespace
Classes: Command, HtmlDialog, Notification, Toolbar, WebDialog
Class Method Summary collapse
- 
  
    
      .add_context_menu_handler {|menu| ... } ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    The add_context_menu_handler method is used to register a block of code with SketchUp that will be called when a context menu is to be displayed. 
- 
  
    
      .beep  ⇒ nil 
    
    
  
  
  
  
  
  
  
  
  
    The beep method plays a system beep sound. 
- 
  
    
      .create_cursor(filename, hot_x, hot_y)  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    The create_cursor method is used to create a cursor from an image file at the specified location. 
- 
  
    
      .inputbox(*args)  ⇒ Array<String>, false 
    
    
  
  
  
  
  
  
  
  
  
    Creates a dialog box for inputting user information. 
- 
  
    
      .inspector_names  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    The inspector_names method is used to returns the names of all the inspectors. 
- 
  
    
      .menu(menu_name = "Plugins")  ⇒ Sketchup::Menu 
    
    
  
  
  
  
  
  
  
  
  
    The UI.menu method retrieves a SketchUp’s menu object with a given name. 
- 
  
    
      .messagebox(message, type = MB_OK)  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    Creates a dialog box containing static text with a series of buttons for the user to choose from. 
- 
  
    
      .model_info_pages  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    The model_info_pages method is used to returns the names of all the available model info pages. 
- 
  
    
      .openpanel(title, directory, filename)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    The openpanel method is used to display the Open dialog box. 
- 
  
    
      .openURL(url)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The UI.openURL method is used to open the default Web browser to a URL. 
- 
  
    
      .play_sound(filename)  ⇒ nil 
    
    
  
  
  
  
  
  
  
  
  
    The play_sound method is used to play a sound file. 
- 
  
    
      .preferences_pages  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    The preferences_pages method is used to returns the names of all the preferences pages. 
- 
  
    
      .refresh_inspectors  ⇒ nil 
    
    
  
  
  
  
  
  
  
  
  
    Tells SketchUp to refresh all inspectors such as the Component Browser and the Outliner. 
- 
  
    
      .refresh_toolbars  ⇒ nil 
    
    
  
  
  
  
  
  
  
  
  
    Tells SketchUp to refresh all floating toolbars. 
- 
  
    
      .savepanel(title, directory, filename)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    The savepanel method is used to display the Save dialog box. 
- 
  
    
      .scale_factor  ⇒ Float 
    
    
  
  
  
  
  
  
  
  
  
    Returns the scaling factor SketchUp uses on high DPI monitors. 
- 
  
    
      .select_directory(options = {})  ⇒ String, ... 
    
    
  
  
  
  
  
  
  
  
  
    The #select_directory method is used to display the OS dialog for selecting one or several directories from the file system. 
- 
  
    
      .set_cursor(cursor_id)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The #UI.set_cursor method is used to change the cursor to a new cursor with a given cursor id. 
- 
  
    
      .set_toolbar_visible(name, visible)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The set_toolbar_visible method is used to set whether a given toolbar is visible. 
- 
  
    
      .show_extension_manager  ⇒ nil 
    
    
  
  
  
  
  
  
  
  
  
    The show_extension_managermethod is used to display the Extension Manager dialog.
- 
  
    
      .show_inspector(name)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The show_inspector method is used to display the inspector with the given name. 
- 
  
    
      .show_model_info(page_name)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The UI.show_model_info method is used to display the model info dialog for a specific page. 
- 
  
    
      .show_preferences(page_name)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The show_preferences method is used to display a SketchUp preferences dialog. 
- 
  
    
      .start_timer(seconds, repeat = false) {|procedure| ... } ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    The start_timer method is used to start a timer. 
- 
  
    
      .stop_timer(id)  ⇒ nil 
    
    
  
  
  
  
  
  
  
  
  
    The stop_timer method is used to stop a timer based on its id. 
- 
  
    
      .toolbar(name)  ⇒ UI::Toolbar 
    
    
  
  
  
  
  
  
  
  
  
    The toolbar method is used to get a Ruby toolbar by name. 
- 
  
    
      .toolbar_names  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    The toolbar_names method is used to return the name of all the available native toolbars (this differs between PC and Mac). 
- 
  
    
      .toolbar_visible?(name)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The toolbar_visible? method is used to determine whether a given toolbar is visible. 
Class Method Details
.add_context_menu_handler {|menu| ... } ⇒ Integer
The add_context_menu_handler method is used to register a block of code with SketchUp that will be called when a context menu is to be displayed. The context menu handler can then display the context menu with the items that you have added.
Be careful with what you do in a context menu handler. If you perform an operation takes take a long time, such as traversing the model or selection in a large model it will delay the menu.
See the contextmenu.rb script in the Plugins/examples directory for an example.
| 39 40 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 39 def self. end | 
.beep ⇒ nil
The beep method plays a system beep sound.
The beep method does not accept any arguments nor return any values.
| 52 53 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 52 def self.beep end | 
.create_cursor(filename, hot_x, hot_y) ⇒ Integer
The create_cursor method is used to create a cursor from an image file at the specified location. This must be called from within a custom Tool. See the Tool class for a complete example.
Since SketchUp 2016 it is possible to provide vector images for the cursors. SVG format for Windows and PDF format for OS X.
| 91 92 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 91 def self.create_cursor(filename, hot_x, hot_y) end | 
.inputbox(prompts, defaults, title) ⇒ Array<String>, false .inputbox(prompts, defaults, list, title) ⇒ Array<String>, false
Creates a dialog box for inputting user information. The dialog box contains input fields with static text prompts, optional default values, optional drop down selections, and optional title.
You can also use this method to display drop down lists of options, by passing an optional param.
| 145 146 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 145 def self.inputbox(*args) end | 
.inspector_names ⇒ Array<String>
The inspector_names method is used to returns the names of all the inspectors. Inspectors are another name for the various floating dialog windows that you can activate from withing SketchUp, such as the Materials window.
| 160 161 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 160 def self.inspector_names end | 
.menu(menu_name = "Plugins") ⇒ Sketchup::Menu
The “Extensions” menu was named “Plugins” prior to SketchUp 2015. For backward compatibility “Plugins” still works.
In versions prior to SketchUp 2018 this would crash if you passed an empty string.
The menu method retrieves a SketchUp’s menu object with a given name. This is the first step toward adding your own custom items to the bottom of SketchUp’s menus.
Valid menu names are: “File”, “Edit”, “View”, “Camera”, “Draw”, “Tools”, “Window”, “Extensions” and “Help”.
| 188 189 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 188 def self.( = "Plugins") end | 
.messagebox(message, type = MB_OK) ⇒ Integer
Creates a dialog box containing static text with a series of buttons for the user to choose from.
Valid message box types are:
- 
MB_OK- Contains an OK button.
- 
MB_OKCANCEL- Contains OK and Cancel buttons.
- 
MB_ABORTRETRYIGNORE- Contains Abort, Retry, and Ignore buttons.
- 
MB_YESNOCANCEL- Contains Yes, No, and Cancel buttons.
- 
MB_YESNO- Contains Yes and No buttons.
- 
MB_RETRYCANCEL- Contains Retry and Cancel buttons.
- 
MB_MULTILINE- Contains and OK button.
Return values can be any of following:
- 
IDOK
- 
IDCANCEL
- 
IDABORT
- 
IDRETRY
- 
IDIGNORE
- 
IDYES
- 
IDNO
In an MB_MULTILINE message box, the message is displayed as a multi-line message with scrollbars (as needed). MB_MULTILNE also allows a third string argument that will be used as the title for the messagebox.
| 232 233 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 232 def self.(, type = MB_OK) end | 
.model_info_pages ⇒ Array<String>
The model_info_pages method is used to returns the names of all the available model info pages. These include UI windows such as Components, Credits, and Units.
| 246 247 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 246 def self.model_info_pages end | 
.openpanel(title, directory, filename) ⇒ String
The openpanel method is used to display the Open dialog box. The path that is returned can then be used inside code to open a text or image file. See the standard Ruby class File for examples of reading and writing from disk.
Bug Fixed in SketchUp 2014: Wildcards were not working properly from SU7 to SU2013. Wildcard filters did not populate the file type dropdown. The filter string would be shown in the file name field with ‘*’ characters converted to ‘_’ characters. Note, the format of a wildcard filter string has been changed.
See the description of the filename parameter below for details.
| 299 300 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 299 def self.openpanel(title, directory, filename) end | 
.openURL(url) ⇒ Boolean
The openURL method is used to open the default Web browser to a URL.
| 259 260 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 259 def self.openURL(url) end | 
.play_sound(filename) ⇒ nil
The play_sound method is used to play a sound file. Valid sound files include .wav and .mp3 files on the Mac and .wav files on the PC.
| 317 318 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 317 def self.play_sound(filename) end | 
.preferences_pages ⇒ Array<String>
The preferences_pages method is used to returns the names of all the preferences pages. These include windows like Extensions.
| 330 331 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 330 def self.preferences_pages end | 
.refresh_inspectors ⇒ nil
Tells SketchUp to refresh all inspectors such as the Component Browser and the Outliner. This is useful when you need to manually force a refresh after you’ve made a change to the document via Ruby. Generally, SketchUp will keep these in sync for you, but occasionally it does not, such as when model.start_operation has disabled UI updates.
| 345 346 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 345 def self.refresh_inspectors end | 
.refresh_toolbars ⇒ nil
Tells SketchUp to refresh all floating toolbars. This is useful when you need to manually force a refresh after you’ve made a change to the document via Ruby. Generally, SketchUp will keep these in sync for you, but occasionally it does not, such as when Sketchup::Model#start_operation has disabled UI updates. This only affects macOS, on Windows the toolbars are always refreshing.
| 361 362 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 361 def self. end | 
.savepanel(title, directory, filename) ⇒ String
The savepanel method is used to display the Save dialog box. The path that is returned can then be used inside code to save out a text or image file. See the standard Ruby class File for examples of reading and writing from disk.
Bug Fixed in SketchUp 2014: Wildcards were not working properly from SU7 to SU2013. Semicolon-separated lists of wildcards did not populate the file type dropdown. The filter string would be shown in the file name field with ‘*’ characters converted to ‘_’ characters.
| 395 396 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 395 def self.savepanel(title, directory, filename) end | 
.scale_factor ⇒ Float
SU2017M0 will automatically scale up line width and text size, but will not scale up the points provided to Sketchup::View#draw2d.
Returns the scaling factor SketchUp uses on high DPI monitors. Useful for things like Sketchup::View#draw2d.
| 419 420 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 419 def self.scale_factor end | 
.select_directory(options = {}) ⇒ String, ...
The #select_directory method is used to display the OS dialog for selecting one or several directories from the file system.
| 462 463 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 462 def self.select_directory( = {}) end | 
.set_cursor(cursor_id) ⇒ Boolean
The #set_cursor method is used to change the cursor to a new cursor with a given cursor id. See UI.create_cursor and the Tool class for details on creating your own tools with arbitrary cursors.
If you call this while a standard SketchUp tool is active, you will not see your custom cursor, as these tools are constantly setting their own cursors to indicate SketchUp’s state.
| 484 485 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 484 def self.set_cursor(cursor_id) end | 
.set_toolbar_visible(name, visible) ⇒ Boolean
The set_toolbar_visible method is used to set whether a given toolbar is visible. Note that the toolbars and their names are different on the Mac vs. PC, so be careful and be sure to test when using this method in a cross-platform script.
| 504 505 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 504 def self.(name, visible) end | 
.show_extension_manager ⇒ nil
The show_extension_manager method is used to display the Extension Manager dialog.
| 516 517 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 516 def self.show_extension_manager end | 
.show_inspector(name) ⇒ Boolean
The show_inspector method is used to display the inspector with the given name. You can get the list of valid inspectors with UI.inspector_names.
| 531 532 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 531 def self.show_inspector(name) end | 
.show_model_info(page_name) ⇒ Boolean
The show_model_info method is used to display the model info dialog for a specific page. You can get the list of valid dialogs with model_info_pages.
- SketchUp 2014
- 
"Classifications"page was added.
- SketchUp 2017
- 
"Extensions"page was removed.
| 550 551 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 550 def self.show_model_info(page_name) end | 
.show_preferences(page_name) ⇒ Boolean
The show_preferences method is used to display a SketchUp preferences dialog. You can get the list of valid dialogs with UI.preferences_pages.
Note that under OSX this method doesn’t currently work.
| 567 568 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 567 def self.show_preferences(page_name) end | 
.start_timer(seconds, repeat = false) {|procedure| ... } ⇒ Integer
The start_timer method is used to start a timer. This is an effective method to create a repeating snippet of code for arbitrary animation.
See this blog post for an detailed example of custom animation using timers: sketchupapi.blogspot.com/2008/10/animate-yo-cheese.html
Note that there is a bug that if you open a modal window in a non-repeating timer the timer will repeat until the window is closed.
| 596 597 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 596 def self.start_timer(seconds, repeat = false) end | 
.stop_timer(id) ⇒ nil
The stop_timer method is used to stop a timer based on its id.
| 612 613 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 612 def self.stop_timer(id) end | 
.toolbar(name) ⇒ UI::Toolbar
The toolbar method is used to get a Ruby toolbar by name. If the toolbar doesn’t exist a new one will be created.
| 627 628 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 627 def self.(name) end | 
.toolbar_names ⇒ Array<String>
The toolbar_names method is used to return the name of all the available native toolbars (this differs between PC and Mac). These toolbar names do not include Ruby toolbars.
| 640 641 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 640 def self. end | 
.toolbar_visible?(name) ⇒ Boolean
The toolbar_visible? method is used to determine whether a given toolbar is visible. Note that the toolbars and their names are different on the Mac vs. PC, so be careful and be sure to test when using this method in a cross-platform script.
| 657 658 | # File 'lib/sketchup-api-stubs/stubs/ui.rb', line 657 def self.(name) end |