Add dimension for a group's outline

I have a group which is not a simple rectangle, its outer shell is not the same as its bounding box, and I want to add a dimension for its outer shell as shown below:


Is there any API that could make this happen?
I’ll upload the component for the test.
test-group.skp (117.7 KB)

:bulb:
"The Drawingelement.#bounds method is used to retrieve the Geom::BoundingBox bounding a Sketchup::Drawingelement.

For a Edge, ComponentInstance and most other Sketchup::Drawingelements, the boundingbox follows the coordinate system the drawing element is placed in. For ComponentDefinition, the box bounds the contents of the component and follows the component’s own internal coordinate system. "

So, perhaps one of the dim can be done like this:

mod = Sketchup.active_model
ents = mod.active_entities
sel = mod.selection
group = sel.first
tr = group.transformation
bb = group.definition.bounds
p0 = bb.corner(0).transform(tr)
p1 = bb.corner(1).transform(tr)
v = p0.vector_to p1
dir_v = v * Z_AXIS
dir_v.length = 20.cm
dim = ents.add_dimension_linear(p0, p1, dir_v)
3 Likes

Yes, this is what I want, thanks!

2 Likes