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(path, 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 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 UI.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_manager
method 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(path, 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(path, 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”, “Help” and “Developer”.
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.
306 307 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 306 def self.openpanel(title, directory, filename) end |
.openURL(url) ⇒ Boolean
The openURL method is used to open the default browser to a URL.
266 267 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 266 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.
324 325 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 324 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 Templates.
- SketchUp 2017
-
"Extensions"
page was removed.
339 340 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 339 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.
354 355 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 354 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.
370 371 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 370 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.
404 405 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 404 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.
428 429 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 428 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.
471 472 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 471 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.
493 494 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 493 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.
513 514 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 513 def self.(name, visible) end |
.show_extension_manager ⇒ nil
The show_extension_manager
method is used to display the Extension Manager dialog.
525 526 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 525 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.
540 541 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 540 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 page names with model_info_pages.
- SketchUp 2014
-
"Classifications"
page was added.
562 563 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 562 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 preferences_pages.
579 580 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 579 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.
608 609 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 608 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.
624 625 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 624 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.
639 640 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 639 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.
652 653 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 652 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.
669 670 |
# File 'lib/sketchup-api-stubs/stubs/ui.rb', line 669 def self.(name) end |