Here is a non-method example. This example uses a mouse context menu command block:
UI.add_context_menu_handler do |popup|
sel = Sketchup::active_model.selection
if !sel.empty? && sel.single_object?
if sel.first.is_a?(Sketchup::ComponentInstance)
popup.add_item("Copy Selected Component to Origin") {
Sketchup::active_model.active_entities.add_instance(
sel.first.definition,
IDENTITY
)
}
end
end
end
Point to a component instance, right-click the mouse, and you should see the menu command at the bottom of the mouse context menu: