Door Bounding Box Dynamo vs API

So when i get a bounding box of a door element in dynamo it gives me a bounding box including the door swing.
EX:


and when i get the bounding box of a door geometry it gives me the bounding box excluding the door swing
EX:


Now using C#
So I take that same logic and i want to get a bounding box around the geometry excluding the door swing…

NOW MY QUESTION!

what does dynamo do differently to get the door geometry. Im assuming it has something to do with excluding the lines that make up the door swing. I don’t even know if this is the right place to post this but i use dynamo all the time and im starting to use C# to make plugins. Please let me know if you can help.

Exactly. A family element already has bounds based on the objects inside it, even if they don’t have geometry (think reference planes). BoundingBox.ByGeometry specifically only looks at physical geometry (it may not even be from Revit elements).

2 Likes

Nick, Thanks for the quick response! So what would be the best way to remove the lines using revit API so i can get the same outcome as dynamo.

I don’t know much about Revit Bounding Boxes so I can only guess. I don’t think you can create a BoundingBoxXYZ from a list of geometries. I think you would have to filter your door geometries to Solids only and get the Bounding Boxes of each individual geometry. Then you could determine the overall minimum and maximum point for those geometries and create a new BoundingBoxXYZ from those.

Someone else may have a way better option though.

1 Like

I’ve been trying to find example code for doors because every time to try it doesn’t find any solids and just returns an error.
Maybe someone could point me to a good example

My attempt…

@ZJRODGERS

    GeometryElement geomElem = elem.get_Geometry(options);

        foreach (var geomObj in geomElem)
        {
            if (geomObj is Solid)
           Continue your code here
1 Like

Another couple of hints to consider: Solved: Solid by union of solids in list - Autodesk Community

1 Like


looks like geoObj is a geometry instance??? I think… Do I iterate through the instances to get to solids?

Yep!

1 Like

@Kulkul for some reason its picking up my instObj as a line…
image

foreach (ElementId elemId in selectedIds)
                        {
                            try
                            {
                                Element elem = uidoc.Document.GetElement(elemId);
                                if ((BuiltInCategory)elem.Category.Id.IntegerValue == BuiltInCategory.OST_Doors)
                                {
                                    allDoors++;

                                    Options opts = new Options();

                                    BoundingBoxXYZ bbDoor = elem.get_BoundingBox(uidoc.Document.ActiveView);
                                    LocationPoint doorCenter = elem.Location as LocationPoint;

                                    GeometryElement geoElem = elem.get_Geometry(opts);

                                    //get geometry object
                                    foreach(GeometryObject geoObj in geoElem)
                                    {
                                        //get instance
                                        GeometryInstance geoInst = geoObj as GeometryInstance;
                                        if(null != geoInst)
                                        {
                                            foreach(GeometryObject instObj in geoInst.SymbolGeometry)
                                            {
                                                Solid solid = instObj as Solid;
                                                BoundingBoxXYZ solidBB = solid.GetBoundingBox();

                                                //gets center bottom of bounding box
                                                XYZ doorMax = new XYZ(solidBB.Max.X, solidBB.Max.Y, solidBB.Min.Z);
                                                XYZ bbDoorCenter = ((doorMax + solidBB.Min) / 2);

                                                //sets family
                                                doc.Create.NewFamilyInstance(bbDoorCenter, firstClearance, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                                                Transform rotDoorTransform = Transform.CreateRotationAtPoint(XYZ.BasisZ, doorCenter.Rotation, bbDoorCenter);

                                            }
                                        }

















                                        

                                       
                                    }
                                    

                                    


                                }

@ZJRODGERS you can remove those null, Line Geometries and get only solids this way:

Good Luck!

3 Likes

Just Incase someone needs this later. Here is what worked for me! Thanks @Kulkul & @jacob.small for the help!

//gets geometry of element
                                    GeometryElement geoElem = elem.get_Geometry(opts);

                                    Solid union = null;


                                    //get geometry object
                                    foreach (GeometryObject geoObj in geoElem)
                                    {
                                        GeometryInstance geoInst = geoObj as GeometryInstance;
                                        if (null != geoInst)
                                        {
                                            
                                            GeometryElement instGeoElem = geoInst.GetInstanceGeometry();
                                            if (instGeoElem != null)
                                            {
                                                foreach (GeometryObject o in instGeoElem)
                                                {
                                                    //find solids & creates union
                                                    Solid solid = o as Solid;
                                                    if (solid != null && 0 < solid.Faces.Size)
                                                    {
                                                        if (null == union)
                                                        {
                                                            union = solid;
                                                        }
                                                        else
                                                        {
                                                            union = BooleanOperationsUtils.ExecuteBooleanOperation(union, solid, BooleanOperationsType.Union);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }


                                    //bounding box around solid
                                    BoundingBoxXYZ solidBB = union.GetBoundingBox();

                                    //sets translation for bounding box
                                    XYZ bbCenter = (solidBB.Max + solidBB.Min) / 2;
                                    XYZ placementpoint = (elem.Location as LocationPoint).Point + bbCenter;
1 Like