Accessing Native Toolbars

I’ve just started dabbling within the UI section of the Ruby API recently, mostly out of curiosity but also because I was fully unaware of a number of powerful methods one has access to.

When I run this small chunk of code in the ruby console:

ObjectSpace.each_object(UI::Toolbar){ |toolbar|
	puts "#{toolbar.name}"
}

It gives me a listing of all the toolbars of all the extensions I have installed within SketchUp. Why does it not give the native toolbars as well?

Are these are not accessible?

The UI #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.

(But I’m not sure there’s anything you can do with them other than get their names…)

… and visibility.

Explanation:

names = UI.toolbar_names
Will returns:

["Camera", "Classifier", "Construction", "Drawing", "Edit", "Getting Started", "Large Tool Set", "Location", "Principal", "Section", "Shadows", "Solid Tools", "Standard", "Styles", "Tags", "Views", "Warehouse"]

For example, if you want to check if the “Camera” toolbar is visible?

UI.toolbar_visible?("Camera")

You will get its (this native toolbar) visibility.

But if you want to get a reference to the native “Camera” toolbar, you need to be careful, because the UI.toolbar(name) method is used to get a Ruby toolbar by name, and not the native toolbar.

Entring this to console:
cam_toolbar = UI.toolbar("Camera")

You will get a new Ruby toolbar object with a name of “Camera”, instead of reference to native one.

toolbar_warning

Its visibility can be checked by Toolbar #visible? instance method:
visible = cam_toolbar.visible?
__
Conclusion:
There are NO Ruby objects for native toolbars!
(?)

The answer is that (obviously) native toolbars are not exposed to Ruby as UI::Toolbar objects.

We have complained about this in the past. That this is an undesirable side affect and should be considered a bug. But I do not see it listed in the API Issue Tracker.

Normally such module getter methods either return an existing member of a collection or nil if it is not found in the collection.

You can also set a native toolbar’s visible state:

status = UI.set_toolbar_visible("Camera", true)
2 Likes

I was hoping it was possible to create my own customized toolbar using some of my own plugin tools and also some native tools but it looks like this is probably impossible at this point.

One cannot alter the native toolbars but can one read them somehow? In other words copy there tools into another (custom) toolbar?

Some ideas:


You can create your own toolbar to execute the native toolbar commands without “reading” them.

You can create a command using the Sketchup.send_action . Valid actions which are initiating some command are listed on the above link. You can also check e.g. this topic for more.

You can use native icons - wich are available in .svg format in all SU version installation directory :
c:\Program Files\SketchUp\SketchUp xxxx\Images\

Example on Windows to mimic Arc tollbar icon ( on Mac you need to use .pdf for icons, or .png on both platform)

toolbar = UI::Toolbar.new "Mytoolbar"

cmd = UI::Command.new("Arc tool") {
  Sketchup.send_action("selectArcTool:")
}
cmd.small_icon = "tb_arc.svg"
cmd.large_icon = "tb_arc.svg"
cmd.tooltip = "Test Toolbars"
cmd.status_bar_text = "Draw Arc...."
cmd.menu_text = "Arc"

# cmd2 = ....

toolbar = toolbar.add_item cmd
#toolbar = toolbar.add_item cmd2

Use: LordOfTheToolbars SketchUp Plugins | PluginStore | SketchUcation

Perhaps @Fredo6 can share some ideas about it.


You can setup your own custom toolbars manually using UI by drag the icons (holding CTRL key copy them) from other toolbars onto the new one.
toolbar_create

In SU2025 it is allowed to use custom toolbar items as well, but unfortunately it is buggy, because if you add 3rd party icons, that will be “lost” after restart. However icons from native Toolbars, will kept. ( see here )

5 Likes

We cannot mix and match, although users have asked to do so for a long time.

As @dezmo points out, we can create Ruby doppelganger commands of native commands and mix them with extension commands.

NOTE, that there are a bunch of native commands IDs defined at the top-level that work on MS Windows. The Mac will need to use the action strings.

We might need to get the path to SketchUp’s images:

path = Sketchup.find_support_file('Images')
icon = File.join(imgs, 'tb_arc.svg')
cmd.small_icon = cmd.large_icon = icon
2 Likes

Maybe I’m too quick in giving up on this, I might just monkey around with this a bit more. At the very least I might learn something.