Adding Flipped Component Instance
-
In the script I am writing I need to add a copy of a flipped component. After selecting the flipped component I use this code but the copy is the same if I have selected the orgional component or flipped component.
@model = Sketchup.active_model @layers = @model.layers @ss = @model.selection @ents = @model.active_entities @entities = @model.entities @pages = @model.pages @count = @pages.count @length = @layers.length @definitions = @model.definitions entity = @ss.first ent_def = entity.definition insert_tran = Geom;;Transformation.new [0,0,0] c2=@model.active_entities.add_instance(ent_def,insert_tran)
Keith
-
You are adding an un-transformed instance with your code.
If you want simply to duplicate whatever is selected then you can group it, copy the group and explode the group... provided it all takes place in the same entities context [akamodel.active_entities
]...gp=@model.active_entities.add_group(entity) cp=@model.active_entities.add_instance(gp.entities.parent, Geom;;Transformation.new()) gp.explode!
Now you have 'cp' which is a group containing an exact duplicate of the selection. IF you know it's one component-instance then
ccopy=cp.entities[0]
thencp.explode!
- you now have a duplicate of 'entity
' referred to as 'ccopy
'... This works for all selected objects... -
Thanks TIG that worked like I wanted it to. Seem a long way around but results are good.
Keith
-
TIG, why are you exploding stuff when the question was about inserting a component instance mirrored? I'm I missing something there?
-
He wanted to copy a selected component-instance [that happens to be mirrored] and was trying to get its definition and place an instance etc.
Obviously he could reuse the original's transformation...***
I was trying to show him how he might copy "anything" that is selected, by grouping it.
The code groups the selection, adds another instance of it and explodes the original.
At that point if he knows the selection was the one component-instance then he has the option to explode its group, giving the same result as placing a second instance using the original's transformation, but if the selection is of something different - e.g. groups, geometry, mixed objects etc - he can choose to do other things with them within the safety of his group - e.g. non-merging geometry is preserved...
***For the avoidance of doubt here is how to duplicate an instance with the same matching transformation [i.e. position,rotation,scaling,mirroring etc]... Assuming that 'instance' is what's been selected/found and it has been tested and found to be a ComponentInstance...
copy_of_instance = instance.parent.entities.add_instance(instance.definition, instance.transformation)
Advertisement