Insert dynamic component from the component folder by a plugin

Hi,
I am a newbie to ruby. I have some dynamic components in my default component folder. I have to add an extension with some buttons to insert a specific component. Is that possible?
I found a simple ruby code for a message box when click an extension button. What I have to change here to insert a specific component.
Here is the ruby I found and it’s working.

Please, don’t post an imagen to show your code, post as this link says…

You need to insert ruby code to be executed in…

cmd = UI::Command.new("Toolbar Button") {
  #Your code here
}
1 Like
toolbar = UI::Toolbar.new "Test"
cmd = UI::Command.new("Test") {
model = Sketchup.active_model
entities = model.active_entities
point = Geom::Point3d.new(10, 20, 30)
transform = Geom::Transformation.new(point)
path = Sketchup.find_support_file("drawers 1.skp", "Components/Drawer/")
definitions = model.definitions
componentdefinition = definitions.load(path)
instance = entities.add_instance(componentdefinition, transform)
}
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

I used as he said. but code is showing like this why?

And It’s working perfectly. thanks. but what I want is, component should come with the cursor until I place it. similar to insert component from component browser. any idea for that?

You have to define a class for pick point. See this exampe https://github.com/SketchUp/sketchup-ruby-api-tutorials/tree/main/examples/02_custom_tool

The Model #place_component method places a new component in the Model using the component placement tool.

2 Likes