How to get the center of a ComponentDefinition array?
-
I have an array of ComponentDefinition. I want to find the center of these ComponentDefinitions.
Maybe I should find the union bounds of these ComponentDefinitions, but I did not find the way ... Could any one help me?
-
I don't understand the question. ComponentDefinitions doesn't exist in modelspace - so I do not see how you would get the centre of a collection of definitions.
Can you describe the abstract of what you are trying to do?
-
If you meant ComponentInstance then they each have bounds.
Make a new empty bounding-box object [bb
], and then add each of theinstance.bounds
to thatbb.add(instance.bounds)
.
The center isbb.center
......... -
@thomthom said:
I don't understand the question. ComponentDefinitions doesn't exist in modelspace - so I do not see how you would get the centre of a collection of definitions.
Can you describe the abstract of what you are trying to do?
I'm sorry I made a mistake, the type is not ComponentDefinition, but a Group. I use the following code:
model = Sketchup.active_model;
groups = [];
model.definitions.each{|d| groups << d if d.group? }
name = "left_head"
pgrp = [];
groups.each{|d| pgrp << d.instances[0] if d.instances[0].name==name }
the type of gprp is Sketchup::Group.Actually, I want to get the center of a group with the group name "left_head", but there are several groups with the name "left_head", so I have to find the union bounding box of them.
-
@tig said:
If you meant ComponentInstance then they each have bounds.
Make a new empty bounding-box object [bb
], and then add each of theinstance.bounds
to thatbb.add(instance.bounds)
.
The center isbb.center
.........Thanks for your tip. I will test the code.
Advertisement