How to assign Components to toolbar icons?

Hi i would like to ask if someone knows how to assign exact component from my local library to an toolbar icon created with toolbar editor.
I dont know Ruby and so therefor i would like to ask for code that i could just copy paste and change the path to component when i need to create next icon with next component assigned to it.
Iam trying to create my library of most used components to be as toolbar so i just click the icon of needed component to get it .
Thanks a lot .

This is quite easy to achieve with a small Ruby snippet.

PATH = "C:/Some/Location/Your/File/Is/Located/At.skp"

def load_component(path)
  model = Sketchup.active_model
  definiton = model.definitions.load(path)
  model.place_component(definition)
end

command = UI::Command.new("Add Component") { load_component(PATH) }
command.tooltip = "Add Component"
command.status_bar_text = "Add a hard-coded component to model."
###command.small_icon = command.large_icon = something

toolbar = UI::Toolbar.new("My Script")
toolbar.add_item(command)
toolbar.restore

The question is why doing this. This aproach scales very badly. If more and more components are added as separate buttons, the toolbar gets wider and wider. The Component browser already handles the general case of inserting components from libraries.

2 Likes

You might wanna have a look at the toolbar editor, too(l):

https://extensions.sketchup.com/nl/content/toolbar-editor

:

thanks @eneroth3 for the quick respond. I am planning to have there just about 10 dynamic components. I will give it a try. might be able to paste the code to toolbar editor and wait what happens. :blush:

thanks @MikeWayzovski that’s exactly what I am trying to use. just don’t know the coding that I could drop in the tool.
unfortunately there is no place in Slovakia I could get help learning ruby. and just by tuts in English i cannot get it in my head.

10 icons is a huge toolbar. Even a full fledge BIM toolset with separate tools for drawing slabs, walls, doors, windows and the like could have a smaller toolbar.

hi @eneroth3,
thanks for the code you shared with me.
when i place it to toolbar editor tool it doesn’t load component but it creates another tool bar “My script” but no component at all.
one of the things I could think about (with zero knowledge of RUBY) is that my component is placed at USB disk under F:
the guesting is if it doesn’t need to be at hArd disk c.

Change PATH into the path of the component file.

i did as first.

Dňa pi 14. 6. 2019, 11:48 Julia Christina Eneroth via SketchUp Forum sketchup@discoursemail.com napísal(a):