Clone a component without inserting it in the model

Is it possible to perform the following operation?

  • Make a copy of an instance of a component
  • Change its axes to match its alignments
  • Extract the measurements from the boundingbox and store them
  • Delete the copied instance

I have been able to do all the operations but I don’t know how to make the copy not to be inserted in the model, only to be treated as a virtual object. ( The purpose is that it does not interact with the rest of the model elements.)

My problem is that if the component that I copy generates openings (for example a window) or has elements that make holes in it (a wall in which there is a hole generated by a window), the component is destroyed.



I have used the method:

component_copied = original_component.copy

#do stuff
#save values into variables


Have you tried …

untransformed_bbox = instance.definition.bounds


The bounding box I want to obtain is the transformed one not the original one
After that I don’t need the copy, only the original component

What about if you create a group first - perhaps with cpoint at the ORIGIN - then create the copy of the original component inside that group (add it to group entities instead of model entities).

(I’m not sure - perhaps you just say a “placeholder” methods, but there is no #copy method for components, only for groups)

I’ll do a test later. It is possible that if I make the copy already in a new group it does not affect the rest of the geometry.
Thanks @dezmo

1 Like

It worked, I needed to make an extra step but it worked. If there was more than one instance of the same component, the problem would happen again.

model_entities = Sketchup.active_model.entities
provGroup = model_entities.add_group(component_copied = original_component.copy.make_unique)

#do stuff
#save values into variables

provGroup.erase! if provGroup
1 Like