class Toolbar

Parent: Object | Class Index
Methods: new, add_item, add_seperator, get_last_state, hide, restore, show, visible? |
Sample Code: toolbartests.rb |

The Toolbar class contains methods to create and manipulate SketchUp toolbars in Ruby.

Class Methods

new
The new method creates a new Toolbar object.
Syntax:
toolbar = UI::Toolbar.new "toolbarname"
Arguments:
"toolbarname" - the name for the new toolbar
Return Value:
toolbar - the newly created toolbar object
Comments:
Example:
toolbar = UI::Toolbar.new "Test"

Instance Methods

add_item
The add_item method is used to add an item to the toolbar.
Syntax:
toolbar = toolbar.add_item command
Arguments:
command - a Command object representing the command to add to the toolbar
Return Value:
toolbar - the toolbar where the command was just added
Comments:
Example:
toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = UI::Command.new($tStrings.GetString("Test")) { helloWorld } cmd.small_icon = "ToolPencilSmall.png" cmd.large_icon = "ToolPencilLarge.png" cmd.tooltip = $tStrings.GetString("Test Toolbars") cmd.status_bar_text = $tStrings.GetString("Testing the toolbars class") cmd.menu_text = $tStrings.GetString("Test") toolbar = toolbar.add_item cmd toolbar.show if (toolbar) UI.messagebox toolbar else UI.messagebox "Failure" end

add_separator
The add_separator method is used to add a line separator to the toolbar.
Syntax:
toolbar = toolbar.add_seperator
Arguments:
Return Value:
toolbar - the toolbar where the line separator was just added
Comments:
Example:
toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = UI::Command.new($tStrings.GetString("Test")) { helloWorld } cmd.small_icon = "ToolPencilSmall.png" cmd.large_icon = "ToolPencilLarge.png" cmd.tooltip = $tStrings.GetString("Test Toolbars") cmd.status_bar_text = $tStrings.GetString("Testing the toolbars class") cmd.menu_text = $tStrings.GetString("Test") toolbar = toolbar.add_item cmd toolbar = toolbar.add_separator cmd2 = UI::Command.new($tStrings.GetString("Test Two")) { helloWorld } cmd2.small_icon = "ToolPencilSmall.png" cmd2.large_icon = "ToolPencilLarge.png" cmd2.tooltip = $tStrings.GetString("Test Toolbars") cmd2.status_bar_text = $tStrings.GetString("Testing the toolbars class") cmd2.menu_text = $tStrings.GetString("Test") toolbar = toolbar.add_item cmd2 toolbar.show if (toolbar) UI.messagebox toolbar else UI.messagebox "Failure" end

get_last_state
The get_last_state method is used to determine if the toolbar is hidden or visible in the user interface.
Syntax:
state = toolbar.get_last_state
Arguments:
Return Value:
state - the last state of the toolbar (see comments)
Comments:
Valid states are 1 for visible, 0 for hidden, -1 for never shown.
Example:
toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = UI::Command.new($tStrings.GetString("Test")) { helloWorld } cmd.small_icon = "ToolPencilSmall.png" cmd.large_icon = "ToolPencilLarge.png" cmd.tooltip = $tStrings.GetString("Test Toolbars") cmd.status_bar_text = $tStrings.GetString("Testing the toolbars class") cmd.menu_text = $tStrings.GetString("Test") toolbar = toolbar.add_item cmd toolbar.show state = toolbar.get_last_state if (state) UI.messagebox state else UI.messagebox "Failure" end

hide
The hide method is used to hide the toolbar on the user interface.
Syntax:
toolbar.hide
Arguments:
Return Value:
Comments:
Example:
toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = UI::Command.new($tStrings.GetString("Test")) { helloWorld } cmd.small_icon = "ToolPencilSmall.png" cmd.large_icon = "ToolPencilLarge.png" cmd.tooltip = $tStrings.GetString("Test Toolbars") cmd.status_bar_text = $tStrings.GetString("Testing the toolbars class") cmd.menu_text = $tStrings.GetString("Test") toolbar = toolbar.add_item cmd toolbar.show UI.messagebox "Toolbar Showing" toolbar.hide UI.messagebox "Toolbar Hidden"

restore
The restore method is used to reposition the toolbar to its previous location and show if not hidden.
Syntax:
toolbar.restore
Arguments:
Return Value:
Comments:
Example:
toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = UI::Command.new($tStrings.GetString("Test")) { helloWorld } cmd.small_icon = "ToolPencilSmall.png" cmd.large_icon = "ToolPencilLarge.png" cmd.tooltip = $tStrings.GetString("Test Toolbars") cmd.status_bar_text = $tStrings.GetString("Testing the toolbars class") cmd.menu_text = $tStrings.GetString("Test") toolbar = toolbar.add_item cmd toolbar.restore

show
The show method is used to display the toolbar in the user interface.
Syntax:
toolbar.show
Arguments:
Return Value:
Comments:
Example:
toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = UI::Command.new($tStrings.GetString("Test")) { helloWorld } cmd.small_icon = "ToolPencilSmall.png" cmd.large_icon = "ToolPencilLarge.png" cmd.tooltip = $tStrings.GetString("Test Toolbars") cmd.status_bar_text = $tStrings.GetString("Testing the toolbars class") cmd.menu_text = $tStrings.GetString("Test") toolbar = toolbar.add_item cmd toolbar.show

visible?
The visible? method is used to determine if the toolbar is currently visible in the user interface.
Syntax:
status = toolbar.visible?
Arguments:
Return Value:
status - true if visible, false if not visible
Comments:
Example:
toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = UI::Command.new($tStrings.GetString("Test")) { helloWorld } cmd.small_icon = "ToolPencilSmall.png" cmd.large_icon = "ToolPencilLarge.png" cmd.tooltip = $tStrings.GetString("Test Toolbars") cmd.status_bar_text = $tStrings.GetString("Testing the toolbars class") cmd.menu_text = $tStrings.GetString("Test") toolbar = toolbar.add_item cmd toolbar.show status = toolbar.visible? if (status) UI.messagebox status else UI.messagebox status end