123456789_123456789_123456789_123456789_123456789_

Class: UI::Toolbar

Relationships
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Enumerable
Inherits: Object

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

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(toolbarname) ⇒ Toolbar

The new method creates a new Toolbar object.

Examples:

toolbar = UI::Toolbar.new "Test"

Parameters:

  • toolbarname (String)

    The name for the new toolbar.

Version:

  • SketchUp 6.0

Instance Attribute Details

#visible?Boolean (readonly)

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

Examples:

visible = toolbar.visible?

Version:

  • SketchUp 6.0

Instance Method Details

#add_item(command) ⇒ Toolbar

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

Examples:

toolbar = toolbar.add_item command

Parameters:

  • command (UI::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_separator(arg) ⇒ Toolbar

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

Version:

  • SketchUp 6.0

#countInteger

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

Examples:

number = toolbar.count

Version:

  • SketchUp 2014

#each {|command| ... } ⇒ nil

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
}

Yield Parameters:

Version:

  • SketchUp 8.0 M1

#get_last_stateBoolean

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:

  • (Boolean)

    the last state of the toolbar (see comments)

Version:

  • SketchUp 6.0

#hidenil

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"

Version:

  • SketchUp 6.0

#lengthInteger

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

Examples:

number = toolbar.length

See Also:

Version:

  • SketchUp 2014

#nameString

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

#restorenil

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

Examples:

toolbar.restore

Version:

  • SketchUp 6.0

#shownil

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

Version:

  • SketchUp 6.0

#sizeInteger

The #size method is an alias of #length.

Examples:

number = toolbar.size

See Also:

Version:

  • SketchUp 2014