<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Revit API get bounding box around door geometry (excluding swing) in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/revit-api-get-bounding-box-around-door-geometry-excluding-swing/m-p/10311360#M26004</link>
    <description>&lt;P&gt;So when i run it it shows solids at first. then i breaks once it hits the line elements i believe.... is there a better way to look at this? i am fairly new to C# trying to learn.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zrodgersTSSSU_0-1620930014244.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/918518iA955C9B0063912AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="zrodgersTSSSU_0-1620930014244.png" alt="zrodgersTSSSU_0-1620930014244.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 May 2021 18:20:54 GMT</pubDate>
    <dc:creator>zrodgersTSSSU</dc:creator>
    <dc:date>2021-05-13T18:20:54Z</dc:date>
    <item>
      <title>Revit API get bounding box around door geometry (excluding swing)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-api-get-bounding-box-around-door-geometry-excluding-swing/m-p/10311235#M26002</link>
      <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&lt;DIV class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center"&gt;&lt;SPAN&gt;So when i get a bounding box of a door element in dynamo it gives me a bounding box including the door swing. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center"&gt;&lt;SPAN&gt;&lt;SPAN&gt;EX:&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zrodgersTSSSU_1-1620925641482.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/918495iCC7C4DD252F1F015/image-size/medium?v=v2&amp;amp;px=400" role="button" title="zrodgersTSSSU_1-1620925641482.png" alt="zrodgersTSSSU_1-1620925641482.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zrodgersTSSSU_2-1620925655585.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/918496i503DA53A98AFB3A7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="zrodgersTSSSU_2-1620925655585.png" alt="zrodgersTSSSU_2-1620925655585.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and when i get the bounding box of a door geometry it gives me the bounding box excluding the door swing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EX:&lt;/SPAN&gt;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zrodgersTSSSU_3-1620925680776.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/918497i53DCAF8293C85E29/image-size/medium?v=v2&amp;amp;px=400" role="button" title="zrodgersTSSSU_3-1620925680776.png" alt="zrodgersTSSSU_3-1620925680776.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zrodgersTSSSU_4-1620925694177.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/918498i379F0561D5DCC918/image-size/medium?v=v2&amp;amp;px=400" role="button" title="zrodgersTSSSU_4-1620925694177.png" alt="zrodgersTSSSU_4-1620925694177.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOW USING C#!!!! so i thought the same logic would apply. I can get the bounding box of the element and it will include the door swing (which i dont want).&lt;/P&gt;&lt;P&gt;I just want a bounding box just around the door geometry. I have been trying to find out why i cant do this with no luck. Here is the error im getting.&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nF3dz.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/918500i82E511087E084AC3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nF3dz.png" alt="nF3dz.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my code:&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

namespace DynamoToRevitPlugin
{
[Transaction(TransactionMode.Manual)]
class RebarClearancesCMU : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        try
        {
            //need to select elements before

            // Get the handle of current document
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            // reference the form
            RebarClearanceCMUForm form = new RebarClearanceCMUForm(uidoc);
            
            // Get the element selection of current document.
            Selection selection = uidoc.Selection;
            ICollection&amp;lt;ElementId&amp;gt; selectedIds = uidoc.Selection.GetElementIds();
            int allDoors = 0;
            int successDoors = 0;
            int allWindows = 0;
            int successWindows = 0;

            //set family to null
            Family family = null;
            //declare path to family
            String familyPath = "C:\\Users\\zrodgers\\Desktop\\Dev\\DynamoToRevitPlugin\\RebarClearanceFamily.rfa";
            //declare empty string
            string str = "";
            
            


            //gets clearance input in inches
            var clearance = (form.clearanceOffset.Value/12);

            if (0 == selectedIds.Count)
            {
                // If no elements selected.
                TaskDialog.Show("Revit", "Select one or more elements before running plugin.");
            }
            else
            {
                
                if (form.ShowDialog() == DialogResult.OK)
                {

                    
                    FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(GraphicsStyle));
                    GraphicsStyle style = collector.Cast&amp;lt;GraphicsStyle&amp;gt;().FirstOrDefault&amp;lt;GraphicsStyle&amp;gt;(gs =&amp;gt; gs.Name.Equals("&amp;lt;Sketch&amp;gt;"));
                    ElementId categoryId = new ElementId(BuiltInCategory.OST_GenericModel);
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Place Family");

                        // load family
                        doc.LoadFamily(familyPath, out family);
                        //get family types from revit
                        FilteredElementCollector colEle = new FilteredElementCollector(doc);
                        colEle.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_GenericModel);

                        //grab first
                        FamilySymbol firstClearance = colEle.FirstElement() as FamilySymbol;
                        //activate family
                        if (!firstClearance.IsActive)
                        {
                            firstClearance.Activate();
                        }
                       

                        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();
                                    opts.IncludeNonVisibleObjects = false;

                                    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)
                                    {
                                        GeometryInstance geoInst = geoObj as GeometryInstance;
                                        if(null !=geoInst)
                                        {
                                            GeometryElement instGeoElem = geoInst.GetInstanceGeometry();
                                            if(instGeoElem != null)
                                            {
                                                foreach (GeometryObject o in instGeoElem)
                                                {
                                                    //find solids
                                                    Solid solid = o 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);

                                                }


                                            }


                                        }

                                    }

                                }

                                else
                                {
                                    if ((BuiltInCategory)elem.Category.Id.IntegerValue == BuiltInCategory.OST_Windows)
                                    {
                                        allWindows++;
                                        BoundingBoxXYZ bbWindows = elem.get_BoundingBox(uidoc.Document.ActiveView);
                                        LocationPoint windowCenter = elem.Location as LocationPoint;
                                        doc.Create.NewFamilyInstance(windowCenter.Point, firstClearance, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

                                    }
                                }


                            }
                            catch(Exception e)
                            {
                                message = e.Message;
                            }
                        }

                        tx.Commit();
                    }
                }
            }

                    return Result.Succeeded;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 13 May 2021 17:12:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-api-get-bounding-box-around-door-geometry-excluding-swing/m-p/10311235#M26002</guid>
      <dc:creator>zrodgersTSSSU</dc:creator>
      <dc:date>2021-05-13T17:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Revit API get bounding box around door geometry (excluding swing)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-api-get-bounding-box-around-door-geometry-excluding-swing/m-p/10311248#M26003</link>
      <description>&lt;P&gt;Below 'solid' will be nothing if 'o' not a solid:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Solid solid = o as Solid;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bounding box you get will be parallel to model space not the element itself i.e. a door on a diagonal wall in relation to Revit internal coordinate space will be larger than the bounding box for the same door on a wall aligned with X or Y axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can perhaps use symbol geometry bounding box (.GetSymbolGeometry) and transform that to get better (tighter) result.&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 17:28:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-api-get-bounding-box-around-door-geometry-excluding-swing/m-p/10311248#M26003</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2021-05-13T17:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Revit API get bounding box around door geometry (excluding swing)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-api-get-bounding-box-around-door-geometry-excluding-swing/m-p/10311360#M26004</link>
      <description>&lt;P&gt;So when i run it it shows solids at first. then i breaks once it hits the line elements i believe.... is there a better way to look at this? i am fairly new to C# trying to learn.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zrodgersTSSSU_0-1620930014244.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/918518iA955C9B0063912AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="zrodgersTSSSU_0-1620930014244.png" alt="zrodgersTSSSU_0-1620930014244.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 18:20:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-api-get-bounding-box-around-door-geometry-excluding-swing/m-p/10311360#M26004</guid>
      <dc:creator>zrodgersTSSSU</dc:creator>
      <dc:date>2021-05-13T18:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Revit API get bounding box around door geometry (excluding swing)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-api-get-bounding-box-around-door-geometry-excluding-swing/m-p/10311846#M26005</link>
      <description>&lt;P&gt;If you are casting to Solid you can check for not null and only extract the bounding box if it isn't null i.e. 'if' statement used with inequality condition (solid != null).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use typeof also:&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#typeof-operator" target="_blank" rel="noopener"&gt;Type-testing operators and cast expression - C# reference | Microsoft Docs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can also use ?. operators with ??.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and-" target="_blank" rel="noopener"&gt;Member access operators and expressions - C# reference | Microsoft Docs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They create lots of ways to chase the null somewhere else but you always have to deal with the null condition where it ends up eventually.&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 23:20:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-api-get-bounding-box-around-door-geometry-excluding-swing/m-p/10311846#M26005</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2021-05-13T23:20:16Z</dc:date>
    </item>
  </channel>
</rss>

