ModraUp Ruby API Documentation Ruby API Reference

Module: UI

Overview

Host interface for menus, dialogs, toolbars, HTML windows, clipboard access, and timers.

Examples:

UI.messagebox("hello")
UI.menu("Plugins").add_item("Beep") { UI.beep }

Defined Under Namespace

Classes: Command, HtmlDialog, HtmlPanel, Notification, Toolbar, WebDialog

Constants # collapse

UI::MB_OK

MB_OK = 0

UI.messagebox:OK only.

Returns:

  • (Integer)

Examples:

UI.messagebox("ok", MB_OK)
UI::MB_OKCANCEL

MB_OKCANCEL = 1

UI.messagebox:OK / Cancel.

Returns:

  • (Integer)

Examples:

UI.messagebox("?", MB_OKCANCEL)
UI::MB_ABORTRETRYIGNORE

MB_ABORTRETRYIGNORE = 2

UI.messagebox:Abort / Retry / Ignore.

Returns:

  • (Integer)

Examples:

UI.messagebox("err", MB_ABORTRETRYIGNORE)
UI::MB_YESNOCANCEL

MB_YESNOCANCEL = 3

UI.messagebox:yes / no / cancel.

Returns:

  • (Integer)

Examples:

UI.messagebox("?", MB_YESNOCANCEL)
UI::MB_YESNO

MB_YESNO = 4

UI.messagebox:Yes / No.

Returns:

  • (Integer)

Examples:

UI.messagebox("?", MB_YESNO)
UI::MB_RETRYCANCEL

MB_RETRYCANCEL = 5

UI.messagebox:Retry / Cancel.

Returns:

  • (Integer)

Examples:

UI.messagebox("?", MB_RETRYCANCEL)
UI::MB_MULTILINE

MB_MULTILINE = 6

UI.messagebox:multi-line text.

Returns:

  • (Integer)

Examples:

UI.messagebox("a\nb", MB_MULTILINE)
UI::IDOK

IDOK = 1

UI.messagebox returns: OK.

Returns:

  • (Integer)

Examples:

UI.messagebox("ok") == IDOK
UI::IDCANCEL

The cancel value corresponding to IDOK.

Returns:

  • (Integer)

Examples:

IDCANCEL  #=> 2
UI::IDABORT

Return value of UI.messagebox when the user chooses Abort.

Returns:

  • (Integer)

Examples:

IDABORT  #=> 3
UI::IDRETRY

Return value of UI.messagebox when the user chooses Retry.

Returns:

  • (Integer)

Examples:

IDRETRY  #=> 4
UI::IDIGNORE

Return value of UI.messagebox when the user chooses Ignore.

Returns:

  • (Integer)

Examples:

IDIGNORE  #=> 5
UI::IDYES

Return value of UI.messagebox when the user chooses Yes.

Returns:

  • (Integer)

Examples:

IDYES  #=> 6
UI::IDNO

Return value of UI.messagebox when the user chooses No.

Returns:

  • (Integer)

Examples:

IDNO  #=> 7
UI::TB_HIDDEN

TB_HIDDEN = 0

The toolbar's last state: Hidden. See UI::Toolbar#get_last_state.

Returns:

  • (Integer)

Examples:

UI::TB_HIDDEN  #=> 0
UI::TB_VISIBLE

TB_VISIBLE = 1

Toolbar last state: Visible.

Returns:

  • (Integer)

Examples:

UI::TB_VISIBLE  #=> 1
UI::TB_NEVER_SHOWN

TB_NEVER_SHOWN = -1

The toolbar has never been shown.

Returns:

  • (Integer)

Examples:

UI::TB_NEVER_SHOWN  #=> -1

Class Method Summary # collapse

Class Method Details

UI.messagebox(message) ⇒ IntegerUI.messagebox(message, type) ⇒ IntegerUI.messagebox(message, type, title) ⇒ Integer

Display a message box. Return IDOK if no host is present.

Parameters:

  • message (String)
  • type (Integer) A button configuration such as MB_OK. Defaults to MB_OK.
  • title (String)

Returns:

Examples:

UI.messagebox("Save?", MB_YESNO, "Confirm")

UI.inputbox(prompts) ⇒ Array<String>, falseUI.inputbox(prompts, defaults) ⇒ Array, falseUI.inputbox(prompts, defaults, title) ⇒ Array, falseUI.inputbox(prompts, defaults, lists, title) ⇒ Array, false

Multiline input. Returns false if canceled or no host. Returns the default value for Integer, Float, and Length types; otherwise, returns the string. Fails with ArgumentError if numerical conversion fails.

Parameters:

  • prompts (Array<String>)
  • defaults (Array<String, Integer, Float, Length>)
  • lists (Array<String>, String) Dropdown options or title
  • title (String)

Returns:

  • (Array<String, Integer, Float, Length>, false)

Raises:

  • [ArgumentError] The input cannot be converted to the default numeric type.

Examples:

UI.inputbox(["Width"], ["1"], "Dimensions")

UI.openpanel(title = "Open", directory = nil, filename = nil) ⇒ String, nil

Open the file dialog box. Return nil if canceled.

Parameters:

  • title (String)
  • directory (String)
  • filename (String)

Returns:

  • (String, nil)

Examples:

path = UI.openpanel("Open", Dir.home, "*.skp")

UI.savepanel(title = "Save", directory = nil, filename = nil) ⇒ String, nil

Save file dialog. Cancel returns nil.

Parameters:

  • title (String)
  • directory (String)
  • filename (String)

Returns:

  • (String, nil)

Examples:

UI.savepanel("Save as", Dir.home, "out.skp")

UI.select_directory(options = {}) ⇒ String, Array<String>, nil

Select directory. Hash key :title / :directory / :select_multiple. Multiple selection returns an array, otherwise returns a path.

Parameters:

  • options (Hash)

Returns:

  • (String, Array<String>, nil)

Examples:

UI.select_directory(title: "Project", directory: Dir.home)

UI.openURL(url) ⇒ Boolean

Open the URL in the system browser.

Parameters:

  • url (String)

Returns:

  • (Boolean)

Examples:

UI.openURL("https://example.com")

UI.beep ⇒ nil

System beep.

Returns:

  • (nil)

Examples:

UI.beep

UI.play_sound(path) ⇒ nil

Plays a local sound file.

Parameters:

  • path (String)

Returns:

  • (nil)

Examples:

UI.play_sound("/System/Library/Sounds/Pop.aiff")

UI.start_timer(seconds, repeat = false) { } ⇒ Integer

Start the timer and return a handle to UI.stop_timer.

Parameters:

  • seconds (Numeric)
  • repeat (Boolean)

Returns:

  • (Integer)

Yields:

  • @yield is called when the timer expires.

Raises:

  • [ArgumentError] Missing seconds or block

Examples:

id = UI.start_timer(0.5, false) { UI.beep }
UI.stop_timer(id)

UI.stop_timer(id) ⇒ nil

Stop the timer returned by UI.start_timer.

Parameters:

  • id (Integer)

Returns:

  • (nil)

Examples:

id = UI.start_timer(10, true) { }
UI.stop_timer(id)

UI.scale_factor ⇒ NumericUI.scale_factor(view) ⇒ Numeric

Returns 1.0 (as of SketchUp 2025, this is compatible padding: screen coordinates are already logical pixels). When passed a {ModraUp::View}, returns the scale factor of the viewport's screen (commonly 2.0 on Retina displays).

Parameters:

  • view (ModraUp::View)

Returns:

  • (Numeric)

Raises:

Examples:

No parameters

UI.scale_factor  #=> 1.0

The display containing the viewport

UI.scale_factor(ModraUp.active_model.active_view)

UI.get_clipboard_data ⇒ String, nil

Read clipboard text.

Returns:

  • (String, nil)

Examples:

UI.get_clipboard_data

UI.set_clipboard_data(text) ⇒ Boolean

Write text to the clipboard.

Parameters:

  • text (String)

Returns:

  • (Boolean)

Examples:

UI.set_clipboard_data("hello")

UI.create_cursor(path, hot_x, hot_y) ⇒ Integer

Create a cursor from an image file and return a handle to UI.set_cursor.

Parameters:

  • path (String)
  • hot_x (Integer)
  • hot_y (Integer)

Returns:

  • (Integer)

Examples:

id = UI.create_cursor(File.join(__dir__, "cursor.png"), 2, 2)
UI.set_cursor(id)

UI.set_cursor(id) ⇒ Boolean

Set the current cursor.

Parameters:

Returns:

  • (Boolean)

Examples:

UI.set_cursor(0)

UI.toolbar(name) ⇒ UI::Toolbar

Retrieve the toolbar by name; if it doesn't exist, create one (category defaults to "Modeling").

Parameters:

  • name (String)

Returns:

  • (UI::Toolbar)

Examples:

UI.toolbar("Test").show

UI.toolbar_names ⇒ Array<String>

The currently registered toolbar names.

Returns:

  • (Array<String>)

Examples:

UI.toolbar_names

UI.toolbar_visible?(name) ⇒ Boolean

Whether the toolbar is visible.

Parameters:

  • name (String)

Returns:

  • (Boolean)

Examples:

UI.toolbar_visible?("Large Tool Set")

UI.set_toolbar_visible(name, visible) ⇒ Boolean

Show or hide the toolbar.

Parameters:

  • name (String)
  • visible (Boolean)

Returns:

  • (Boolean)

Examples:

UI.set_toolbar_visible("Test", true)

UI.refresh_toolbars ⇒ nil

Recalculate the enabled and checked states of the Ruby toolbar commands.

Returns:

  • (nil)

Examples:

UI.refresh_toolbars

UI.refresh_inspectors ⇒ nil

Refresh the inspectors panel.

Returns:

  • (nil)

Examples:

UI.refresh_inspectors

UI.inspector_names ⇒ Array<String>

Names of inspectors that can be opened.

Returns:

  • (Array<String>)

Examples:

UI.inspector_names

UI.show_inspector(name) ⇒ Boolean

Open the specified inspector.

Parameters:

  • name (String)

Returns:

  • (Boolean)

Examples:

UI.show_inspector("Entity Info")

UI.model_info_pages ⇒ Array<String>

The page name for the model information dialog.

Returns:

  • (Array<String>)

Examples:

UI.model_info_pages

UI.show_model_info(page) ⇒ Boolean

Open the model information and switch to that page.

Parameters:

  • page (String)

Returns:

  • (Boolean)

Examples:

UI.show_model_info("Units")

UI.preferences_pages ⇒ Array<String>

Name of the preference settings page.

Returns:

  • (Array<String>)

Examples:

UI.preferences_pages

UI.show_preferences(page) ⇒ Boolean

Open the preferences and switch to that page.

Parameters:

  • page (String)

Returns:

  • (Boolean)

Examples:

UI.show_preferences("Extensions")

UI.show_extension_manager ⇒ nil

Open the Extension Manager.

Returns:

  • (nil)

Examples:

UI.show_extension_manager

UI.show_extension_warehouse ⇒ nilUI.show_extension_warehouse(id) ⇒ nil

Open the Extension Warehouse (optionally navigate to a specific extension id).

Parameters:

  • id (String)

Returns:

  • (nil)

Examples:

UI.show_extension_warehouse

UI.add_context_menu_handler {|menu| } ⇒ Integer

Right-click menu callback. Called by default on a right-click in the viewport when hitting a solid entity; not called if the current tool implements ModraUp::Tool#getMenu for blank areas or the current tool. The block receives a ModraUp::Menu, which can be used to add items with ModraUp::Menu#add_item, submenus with ModraUp::Menu#add_submenu, or separators with ModraUp::Menu#add_separator.

Returns:

  • (Integer) Processor ID

Yields:

  • @yieldparam menu [ModraUp::Menu]

Raises:

  • [ArgumentError] No block provided

Examples:

UI.add_context_menu_handler do |menu|
  menu.add_item("Beep") { UI.beep }
  sub = menu.add_submenu("Dynamic Components")
  sub.add_item("Redraw") { UI.beep }
end