How to set component's parent

new_component_instance.parent = Sketchup.active_model

Error: #<NoMethodError: undefined method `parent=’ for #Sketchup::ComponentInstance:0x007fdbf4a34418>

You can’t do that. The parent of a componentInstance is its ComponentDefinition.

Unlike ‘C’, Ruby does not allow direct assignment of class variables. It would require a “parent=” method setter, and the API does not support that. Drawing elements are added to components via the “add_ . . .” methods of the entities class. That allows Sketchup to internally manage parents.

1 Like

thank you for your reply. i means that could i change the layer of component instance to the child of active_model.

now i have solve it. I just do this.

Sketchup.active_model.entities.add_instance(component_instance.definition, component_instance.transformation)

then the component instance becomes the child of active_model.

thank you.

No, you are creating another instance of the same definition. You will now have 2 of them.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.