Doesn't get the minimal bounding box from the solid of the structural column

yuvdal
Enthusiast
Enthusiast

Doesn't get the minimal bounding box from the solid of the structural column

yuvdal
Enthusiast
Enthusiast

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:

yuvdal_0-1654090220102.png

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.

yuvdal_4-1654090938889.png

 

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.

yuvdal_2-1654090895918.png

yuvdal_6-1654090963256.png

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

 

0 Likes
Reply
427 Views
1 Reply
Reply (1)

jeremy_tammik
Autodesk
Autodesk

Dear Yuval,

 

You seem to be repeating the same question I already answered in this previous recent thread:

 

 

Remember: a bounding box is a bounding box. There is no guarantee that a bounding box is minimal. Never.

 

The main purpose of a bounding box is speed, not accuracy, and definitely not to be minimal.

 

Since you can never assume that a bounding box is minimal, and if this is causing an issue with your code, I would recommend checking whether is is erroneously making this assumption. If it is, it might be safer to fix it.

 

If your application requires a minimal bounding box, the safest way to obtain it is to query the element geometry for all its vertices and create a convex hull or truly minimal bounding box from those.

 

I described an approach to retrieve the element geometry vertices in this other recent discussion:

 

 

I would create a list of unique values while iterating over all the face vertices. The Building Coder demonstrates several variations of this with methods such as GetVertices in CmdNestedInstanceGeo.cs:

 

 

I hope this clarifies.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes