Class: UI::Toolbar

Inherits:
Object
  • Object
show all
Includes:
Enumerable

Overview

The Toolbar class contains methods to create and manipulate SketchUp toolbars in Ruby. Toolbars are collections of buttons that you can use to activate custom Tools or ruby scripts.

Also see the Command object for details on creating “commands” which can be called from your toolbars.

Examples:

toolbar = UI::Toolbar.new "Test"
# This toolbar icon simply displays Hello World on the screen
cmd = UI::Command.new("Test") {
  UI.messagebox "Hello World"
}
cmd.small_icon = "ToolPencilSmall.png"
cmd.large_icon = "ToolPencilLarge.png"
cmd.tooltip = "Test Toolbars"
cmd.status_bar_text = "Testing the toolbars class"
cmd.menu_text = "Test"
toolbar = toolbar.add_item cmd
toolbar.show

Version:

  • SketchUp 6.0

Class Method Summary # collapse

Instance Method Summary # collapse

Class Method Details

.new(toolbarname) ⇒ Object

The new method creates a new Toolbar object.

Examples:

toolbar = UI::Toolbar.new "Test"

Returns toolbar - the newly created toolbar object

Parameters:

  • toolbarname

    The name for the new toolbar.

Returns:

  • toolbar - the newly created toolbar object

Version:

  • SketchUp 6.0

Instance Method Details

#add_item(command) ⇒ Object

The add_item method is used to add an item to the toolbar.

Examples:

toolbar = toolbar.add_item command

Returns toolbar - the toolbar where the command was just added

Parameters:

  • command

    A Command object representing the command to add to the toolbar.

Returns:

  • toolbar - the toolbar where the command was just added

Version:

  • SketchUp 6.0

#add_separatorObject

The add_separator method is used to add a line separator to the toolbar.

Examples:

toolbar = toolbar.add_separator

Returns toolbar - the toolbar where the line separator was just added

Returns:

  • toolbar - the toolbar where the line separator was just added

Version:

  • SketchUp 6.0

#countInteger

The #count method is inherited from the Enumerable mix-in module.

Examples:

number = toolbar.count

Returns:

  • (Integer)

Version:

  • SketchUp 2014

#each {|key, value| ... } ⇒ Object

The each method is used to iterate through all of the commands attached to a toolbar.

Examples:

toolbar = UI::Toolbar.new "Test"
# This command displays Hello World on the screen when clicked
cmd = UI::Command.new("Test") { UI.messagebox("Hello World") }
toolbar.add_item cmd
toolbar = toolbar.add_separator
cmd = UI::Command.new("Test 2") { UI.messagebox("Hello World 2") }
toolbar.add_item cmd
toolbar.show
toolbar.each { | item |
  puts item
}

Yields:

  • (key, value)

    Variables that will hold each key and value as they are found.

Returns:

  • nil

Version:

  • SketchUp 8.0 M1

#get_last_stateObject

The get_last_state method is used to determine if the toolbar was hidden or visible in the previous session of SketchUp.

Valid states are 1 for visible, 0 for hidden, -1 for before never shown.

Examples:

state = toolbar.get_last_state

Returns:

  • state - the last state of the toolbar (see comments)

Version:

  • SketchUp 6.0

#hideObject

The hide method is used to hide the toolbar on the user interface.

Examples:

toolbar = UI::Toolbar.new "Test"
# This toolbar icon simply displays Hello World on the screen
cmd = UI::Command.new("Test") {
  UI.messagebox "Hello World"
}
cmd.small_icon = "ToolPencilSmall.png"
cmd.large_icon = "ToolPencilLarge.png"
cmd.tooltip = "Test Toolbars"
cmd.status_bar_text = "Testing the toolbars class"
cmd.menu_text = "Test"
toolbar = toolbar.add_item cmd
toolbar.show
UI.messagebox "Toolbar Showing"
toolbar.hide
UI.messagebox "Toolbar Hidden"

Returns:

  • nil

Version:

  • SketchUp 6.0

#lengthInteger

The #length method returns the number of items in the toolbar.

Examples:

number = toolbar.length

Returns:

  • (Integer)

See Also:

Version:

  • SketchUp 2014

#nameObject

The name method returns the name of the toolbar.

Examples:

toolbar = UI::Toolbar.new "Test"
# This command displays Hello World on the screen when clicked
cmd = UI::Command.new("Test") { UI.messagebox("Hello World") }
toolbar.add_item cmd
toolbar = toolbar.add_separator
cmd = UI::Command.new("Test 2") { UI.messagebox("Hello World 2") }
puts toolbar.name
toolbar.show

Returns:

  • string - the name of the toolbar.

Version:

  • SketchUp 8.0 M1

#restoreObject

The restore method is used to reposition the toolbar to its previous location and show if not hidden.

Examples:

toolbar.restore

Returns:

  • nil

Version:

  • SketchUp 6.0

#showObject

The show method is used to display the toolbar in the user interface.

Examples:

toolbar = UI::Toolbar.new "Test"
# This toolbar icon simply displays Hello World on the screen
cmd = UI::Command.new("Test") {
  UI.messagebox "Hello World"
}
cmd.small_icon = "ToolPencilSmall.png"
cmd.large_icon = "ToolPencilLarge.png"
cmd.tooltip = "Test Toolbars"
cmd.status_bar_text = "Testing the toolbars class"
cmd.menu_text = "Test"
toolbar = toolbar.add_item cmd
toolbar.show

Returns:

  • nil

Version:

  • SketchUp 6.0

#sizeInteger

The #size method is an alias of #length.

Examples:

number = toolbar.size

Returns:

  • (Integer)

See Also:

Version:

  • SketchUp 2014

#visible?Object

The visible? method is used to find out if a toolbar is currently visible.

Examples:

visible = toolbar.visible?

Returns:

  • true if visible

  • (Boolean)

Version:

  • SketchUp 6.0