Module: UI
Relationships | |
Namespace Children | |
Classes:
|
Overview
The UI module contains a number of methods for creating simple UI
elements from a SketchUp Ruby script.
Class Method Summary
-
.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.
-
.get_clipboard_data ⇒ String?
Returns the plain text available on the clipboard, if there is any.
-
.inputbox(prompts, defaults, title) ⇒ 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 = "Extensions") ⇒ Sketchup::Menu
The .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 .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 .select_directory method is used to display the OS dialog for selecting one or several directories from the file system.
-
.set_clipboard_data(data) ⇒ Boolean
Copies plain text to the clipboard.
-
.set_cursor(cursor_id) ⇒ Boolean
The .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 .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
.beep ⇒ nil
The beep method plays a system beep sound.
The beep method does not accept any arguments nor return any values.
.create_cursor(path, hot_x, hot_y) ⇒ Integer
Since SketchUp 2016 it is possible to provide vector images for the cursors. SVG format for Windows and PDF format for macOS. This is the recommended format to use since it will scale well with different DPI scaling.
Because the image is never released, avoid creating new cursors for the same image for any given tool. Cache it and reuse it.
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 ::Sketchup::Tool
documentation for a complete example.
The size of the cursor images should be 32x32 pixels.
The coordinates for the cursor’s hotspot is based from it’s top left corner. For example, a value of (hot_x, hot_y) = (5, 10) would identify the hotpoint of the cursor at 6 pixels from the left edge of your cursor image and 11 pixels from the top edge of your cursor image.
.get_clipboard_data ⇒ String?
Returns the plain text available on the clipboard, if there is any.
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.
.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.
.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.
.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.
.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.
.openURL(url) ⇒ Boolean
The .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. Valid sound files include .wav and .mp3 files on the Mac and .wav files on the PC.
.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.
.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.
.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.
.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.
.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.
.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_clipboard_data(data) ⇒ Boolean
Copies plain text to the clipboard.
.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.
.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.
.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. You can get the list of valid inspectors with UI
.inspector_names.
.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.
.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.
.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.
.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. If the toolbar doesn’t exist a new one will be created.
.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.
.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.