Doesn't get the minimal bounding box from the solid of the structural column
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to get the bounding box from the solid of structural column but unfortunately, I don't get the minimal one.
In order to demonstrate it, I modeled in-place the following structural column:
Then I tried to run the following function that gets the bounding boxes from all the solids and merges them. In order to show the result, I display the bounding box.
// Application context
var uidoc = commandData.Application.ActiveUIDocument;
var doc = uidoc.Document;
var selectionReference = uidoc.Selection.PickObject(ObjectType.Element);
var selectionElement = doc.GetElement(selectionReference);
//Override the options to use Fine detail level
List<BoundingBoxXYZ> solidsBoundingBoxes = new List<BoundingBoxXYZ>();
Options options = new Options { ComputeReferences = true, DetailLevel = ViewDetailLevel.Fine };
GeometryElement geometryElement = selectionElement.get_Geometry(options);
foreach (GeometryObject geomObject in geometryElement)
{
// You can obtain wall solid with method in the top but some other elements need this type conversion
if (geomObject is GeometryInstance geomInst)
{
// Instance geometry is obtained so that the intersection works as
// expected without requiring transformation
GeometryElement instElem = geomInst.GetInstanceGeometry();
foreach (GeometryObject instObj in instElem)
{
if (instObj is Solid innerSolid)
{
if (innerSolid.Volume > 0)
{
BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();
XYZ bBoxOrigin = innerSolid.GetBoundingBox().Transform.Origin;
boundingBox.Max = innerSolid.GetBoundingBox().Max + bBoxOrigin;
boundingBox.Min = innerSolid.GetBoundingBox().Min + bBoxOrigin;
solidsBoundingBoxes.Add(boundingBox);
}
}
}
}
}
//Get the surrounding bounding boxes that were collected by finding the lowest min point and highest max point
BoundingBoxXYZ surroundingBoundingBox = GetBoundingBoxUtils.GetSurroundingBoundingBox(solidsBoundingBoxes);
// Display the Merged Bounding Box from the Solids
var elem = DisplayUtils.DisplayBoundingBox(surroundingBoundingBox);
The problem is that the bounding box that I get from the solids is not the minimal one. There is an offset of 1/16" from each side of the structural column.
I'm trying to figure out what I'm missing, because for comparison when I run a similar graph in Dynamo, it shows me the correct bounding box from the solids.
I would be glad if someone could help me understand what the difference is between what I do in the code and the Dynamo graph.
Thanks a lot,
Yuval