How to implement function "save as" from right click on selected component?

In large scene, I selected one component and right click then I can save the selected component as a skp file by “Save as…”.
Who know how to implement this function “save as” by ruby api?
Thanks in advance.

The ComponentDefinition #save_as method is used to save your definition as a SketchUp file at the specified file destination.

1 Like

I had try below command but it is not save the whole component.How to save the whole selected component?
definitions = Sketchup.active_model.definitions[0]
status = definitions.save_as(“C:\Users\CTDS002\Desktop\3.skp”)

Select the desired component instance then:

model = Sketchup.active_model
selection = model.selection
definition = selection.first.definition
status = definition.save_as("c:/Users/CTDS002/Desktop/3.skp")
4 Likes

It is working now.Thank you very much.

In a practical example, you may also need some checks to see if the selection contains a single component, and otherwise show an error message.

if selection.size == 1 && selection.first.is_a?(Sketchup::ComponentInstance)
  # Do the thing!
else
  UI.messagebox("Please select a component and try again.")
end
1 Like

Now, … also saving the definition will not bake the instance’s scaling or rotation into what is saved, as the definition’s entities are untransformed.

If you need the instance’s transformation, then see this other recent topic:

1 Like

Thanks for you response.

Thank you very much.