Module: UI
概述
UI模块包含了一些从SketchUp Ruby脚本中创建简单UI元素的方法。
在命名空间下定义的
类: Command,HtmlDialog,HtmlDialog,Toolbar,WebDialog
类方法摘要# 崩溃
-
.add_context_menu_handler{|menu| ... } ⇒ Integer
add_context_menu_handler方法是用来在SketchUp上注册一个代码块,当需要显示上下文菜单的时候,这个代码块会被调用。
-
.beep⇒ nil
beep方法会播放一个系统提示音。
-
.create_cursor(path, hot_x, hot_y) ⇒ Integer
create_cursor方法用于从指定位置的图像文件中创建一个光标。
-
.inputbox(*args) ⇒ Array<String>, false
创建一个用于输入用户信息的对话框。
-
.inspector_names⇒ Array<String>
的UI. inspector_names方法用于返回所有检查器的名称。
-
.menu(menu_name = "Plugins") ⇒ Sketchup::Menu
的UI.menu方法检索一个给定名称的SketchUp的菜单对象。
-
.messagebox(message, type = MB_OK) ⇒ Integer
创建一个包含静态文本和一系列按钮的对话框,供用户选择。
-
.model_info_pages⇒ Array<String>
model_info_pages方法用于返回所有可用的模型信息页面的名称。
-
.openpanel(title, directory, filename) ⇒ String
用于返回所有可用的模型信息页面的名称。UI.openpanel方法用于显示打开对话框。
-
.openURL(url) ⇒ Boolean
该UI.openURL方法用于打开默认的浏览器到一个URL。
-
.play_sound(文件名) ⇒ nil
play_sound方法用于播放一个声音文件。
-
.preferences_pages⇒ Array<String>
preferences_pages方法用于返回所有偏好页面的名称。
-
.Refresh_inspectors⇒ nil
告诉SketchUp刷新所有的检查器,比如说组件浏览器和Outliner。
-
.refresh_toolbars⇒ nil
告诉SketchUp刷新所有的浮动工具条。
-
.savepanel(title, directory, filename) ⇒ String
的UI.savepanel方法用于显示保存对话框。
-
.scale_factor⇒ Float
返回SketchUp在高DPI显示器上使用的缩放系数。
-
.select_directory(options = {}) ⇒ String, ...
的UI.select_directory方法用于显示操作系统对话框,从文件系统中选择一个或几个目录。
-
.set_cursor(cursor_id) ⇒ Boolean
该UI.set_cursor方法是用来改变游标到一个新的游标,并给定一个游标ID。
-
.set_toolbar_visible(name, visible) ⇒ Boolean
set_toolbar_visible方法用于设置一个给定的工具栏是否可见。
-
.show_extension_manager⇒ nil
该方法
show_extension_manager
方法用于显示扩展管理器对话框。 -
.show_inspector(name) ⇒ Boolean
该UI.show_inspector方法用于显示具有给定名称的检查器。
-
.show_model_info(page_name) ⇒ Boolean
该UI.show_model_info方法用于显示一个特定页面的模型信息对话框。
-
.show_preferences(page_name) ⇒ Boolean
show_preferences方法是用来显示SketchUp的偏好对话框的。
-
.start_timer(seconds, repeat = false) {|procedure| ... } ⇒ 整数
start_timer方法用来启动一个定时器。
-
.stop_timer(id) ⇒ nil
stop_timer方法用于停止一个基于id的定时器。
-
.toolbar(name) ⇒ UI::Toolbar
toolbar方法用于根据名称获得一个Ruby工具条。
-
.toolbar_names⇒ Array<String>
toolbar_names方法用于返回所有可用的本地工具条的名称(这在PC和Mac之间有所不同)。
-
.toolbar_visible?(name) ⇒ Boolean
toolbar_visible? 方法用于确定一个给定的工具栏是否可见。
类方法细节
↑.add_context_menu_handler{|menu| ... } ⇒Integer
add_context_menu_handler方法是用来向SketchUp注册一个代码块,当需要显示上下文菜单的时候,这个代码块会被调用。然后上下文菜单处理程序可以显示你所添加的项目的上下文菜单。
请注意你在上下文菜单处理程序中的操作。如果你执行一个需要很长时间的操作,比如在一个大的模型中遍历模型或选择,它将延迟菜单。
参见Plugins/examples目录下的contextmenu.rb脚本,以获得一个例子。
↑.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
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.
↑ .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.
↑.inspector_names⇒Array<String>
Theinspector_namesmethod 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.
↑.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.
Themenumethod 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”.
↑.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 anMB_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
Theopenpanelmethod 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.
↑.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 whenSketchup::Model#start_operationhas disabled UI updates. This only affects macOS, on Windows the toolbars are always refreshing.
↑.savepanel(title, directory, filename) ⇒String
Thesavepanelmethod 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 toSketchup::View#draw2d.
Returns the scaling factor SketchUp uses on high DPI monitors. Useful for things likeSketchup::View#draw2d.
↑.select_directory(options = {}) ⇒String, ...
Theselect_directorymethod is used to display the OS dialog for selecting one or several directories from the file system.
↑.set_cursor(cursor_id) ⇒Boolean
Theset_cursormethod 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
Theshow_extension_manager
method is used to display the Extension Manager dialog.
↑.show_inspector(name) ⇒Boolean
Theshow_inspectormethod 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
Theshow_model_infomethod is used to display the model info dialog for a specific page. You can get the list of valid page names withmodel_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 withpreferences_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.