Hi,
Here's my code I use to get the bounding volume from a Part. The BoundingVolume is a simple custom class that contains the X,Y,Z dimensions with the Volume.
public static BoundingVolume GetOrientedRangingBox(PartDocument partDocument)
{
//assume partDocument exists
var bodies = partDocument.ComponentDefinition.SurfaceBodies.Cast<SurfaceBody>();
TransientBRep transientBRep = AddInServer.InvApp.TransientBRep;
SurfaceBody? combinedBodies = null;
if (bodies != null && bodies.FirstOrDefault() is SurfaceBody baseBody)
{
combinedBodies = transientBRep.Copy(baseBody);
if (bodies.Count() > 1)
{
foreach (SurfaceBody body in bodies.Skip(1))
{
if (body.IsSolid)
{
transientBRep.DoBoolean(combinedBodies, body, BooleanTypeEnum.kBooleanTypeUnion);
}
}
}
}
if (combinedBodies is null) return new BoundingVolume(0, 0, 0);
var orientedBox = combinedBodies.OrientedMinimumRangeBox;
//Autodesk internal dimensions are always centimeter
double[] dimensions = new double[] {orientedBox.DirectionOne.Length * 10, orientedBox.DirectionTwo.Length * 10, orientedBox.DirectionThree.Length * 10}.OrderByDescending(x => x).ToArray();
return new BoundingVolume(dimensions[0], dimensions[1], dimensions[2]);
}
This method cares not for your part to be aligned with the axis system.