Exemplo n.º 1
0
 /// <summary>
 /// Splits RevitElement by level elevations
 /// </summary>
 /// <param name="revitElement">The RevitElement to split</param>
 /// <param name="bottomElev">The bottom elevation of the RevitElement</param>
 /// <param name="topElev">The top elevation of the RevitElement</param>
 /// <param name="height">The height of the RevitElement</param>
 private void SplitByLevels(RevitElement revitElement, double bottomElev, double topElev, double height)
 {
     try
     {
         // if the bottom of the column is below the lowest level, assign it to that level
         if (a_levelData.Count > 0 && a_levelData[0].Item1 > bottomElev && a_levelData[0].Item1 <= topElev)
         {
             string associatedLevel = GetMappedLevel(a_levelData[0].Item2);
             double length          = a_levelData[0].Item1 - bottomElev;
             double volume          = (length / height) * revitElement.Volume;
             a_revitElementData.Add(new RevitElement(revitElement.Category, revitElement.Id, revitElement.Name, associatedLevel, a_levelData[0].Item1, volume, revitElement.MaterialName, revitElement.Material, revitElement.Density));
         }
         var x = 1;
         while (x < this.a_levelData.Count)
         {
             // column base is below level, above or at level below, and column top is above or at level
             if (bottomElev < a_levelData[x].Item1 && bottomElev >= a_levelData[x - 1].Item1 && topElev >= a_levelData[x].Item1)
             {
                 string associatedLevel = GetMappedLevel(a_levelData[x].Item2);
                 double length          = a_levelData[x].Item1 - bottomElev;
                 double volume          = (length / height) * revitElement.Volume;
                 a_revitElementData.Add(new RevitElement(revitElement.Category, revitElement.Id, revitElement.Name, associatedLevel, a_levelData[x].Item1, volume, revitElement.MaterialName, revitElement.Material, revitElement.Density));
             }
             else // column base is below or at level below and column top is above or at level
             {
                 if (bottomElev <= a_levelData[x - 1].Item1 && topElev >= a_levelData[x].Item1)
                 {
                     string associatedLevel = GetMappedLevel(a_levelData[x].Item2);
                     double length          = a_levelData[x].Item1 - a_levelData[x - 1].Item1;
                     double volume          = (length / height) * revitElement.Volume;
                     a_revitElementData.Add(new RevitElement(revitElement.Category, revitElement.Id, revitElement.Name, associatedLevel, a_levelData[x].Item1, volume, revitElement.MaterialName, revitElement.Material, revitElement.Density));
                 }
                 else // column base is below or at level below, column top is above level below, column top is below or at level
                 {
                     if (bottomElev <= a_levelData[x - 1].Item1 && topElev > a_levelData[x - 1].Item1 && topElev <= a_levelData[x].Item1)
                     {
                         string associatedLevel = GetMappedLevel(a_levelData[x].Item2);
                         double length          = topElev - a_levelData[x - 1].Item1;
                         double volume          = (length / height) * revitElement.Volume;
                         a_revitElementData.Add(new RevitElement(revitElement.Category, revitElement.Id, revitElement.Name, associatedLevel, a_levelData[x].Item1, volume, revitElement.MaterialName, revitElement.Material, revitElement.Density));
                     }
                 }
             }
             x++;
         }
         //if the top of the column is above the highest level, assign it to that level
         if (a_levelData.Count > 0 && a_levelData[a_levelData.Count - 1].Item1 < topElev)
         {
             string associatedLevel = GetMappedLevel(a_levelData[a_levelData.Count - 1].Item2);
             double length          = topElev - a_levelData[a_levelData.Count - 1].Item1;
             double volume          = (length / height) * revitElement.Volume;
             a_revitElementData.Add(new RevitElement(revitElement.Category, revitElement.Id, revitElement.Name, associatedLevel, a_levelData[a_levelData.Count - 1].Item1, volume, revitElement.MaterialName, revitElement.Material, revitElement.Density));
         }
     }
     catch (Exception e)
     {
         string m = e.Message;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Read all BuiltInCategory.OST_StructuralColumns elements from a Revit model.
        /// </summary>
        private void ReadColumns()
        {
            var collector       = new FilteredElementCollector(a_doc);
            var filterCategory  = new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns);
            var filterNotSymbol = new ElementClassFilter(typeof(FamilySymbol), true);
            var filter          = new LogicalAndFilter(filterCategory, filterNotSymbol);
            var elements        = collector.WherePasses(filter).ToElements();

            foreach (var element in elements)
            {
                try
                {
                    if (element is FamilyInstance && CheckElementPhase(element))
                    {
                        var revitElement = new RevitElement();
                        revitElement.Category = RevitCategory.Column;
                        revitElement.Id       = element.Id.ToString();
                        revitElement.Name     = element.Name;

                        var   baseLevelParam = element.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);
                        Level baseLevel      = baseLevelParam != null?a_doc.GetElement(baseLevelParam.AsElementId()) as Level : null;

                        revitElement.AssociatedLevel     = baseLevel != null ? baseLevel.Name : a_unknownLevelName;
                        revitElement.AssociatedElevation = baseLevel != null ? baseLevel.ProjectElevation : a_unknownLevelElevation;
                        revitElement.AssociatedLevel     = GetMappedLevel(revitElement.AssociatedLevel);

                        var elementVolume = element.GetParameters("Volume");
                        revitElement.Volume = elementVolume.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(elementVolume[0].AsDouble(), DisplayUnitType.DUT_CUBIC_FEET) : 0.0;
                        var framingStructuralMaterial = this.GetStructuralMaterialFromElement(element, a_doc);
                        revitElement.MaterialName = framingStructuralMaterial != null ? framingStructuralMaterial.Name : "";
                        revitElement.Material     = framingStructuralMaterial != null?GetMaterialType(framingStructuralMaterial) : MaterialType.Unknown;

                        double density = framingStructuralMaterial != null?GetDensity(framingStructuralMaterial) : 0.0;

                        revitElement.Density = density;

                        // Split Column by Levels
                        var colCurve = CreateColumnCurve(element as FamilyInstance);
                        if (colCurve != null && a_levelData.Count > 0)
                        {
                            var basePt    = colCurve.GetEndPoint(0);
                            var topPt     = colCurve.GetEndPoint(1);
                            var trueBel   = basePt.Z;
                            var trueTel   = topPt.Z;
                            var colHeight = trueTel - trueBel;
                            SplitByLevels(revitElement, trueBel, trueTel, colHeight);
                        }
                        else
                        {
                            a_revitElementData.Add(revitElement);
                        }
                    }
                }
                catch (Exception e)
                {
                    ShowElementErrorMessage(element, e);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Read all BuiltInCategory.OST_StructuralFraming elements from a Revit model.
        /// </summary>
        private void ReadFramings()
        {
            var collector       = new FilteredElementCollector(a_doc);
            var filterCategory  = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
            var filterNotSymbol = new ElementClassFilter(typeof(FamilySymbol), true);
            var filter          = new LogicalAndFilter(filterCategory, filterNotSymbol);
            var elements        = collector.WherePasses(filter).ToElements();

            foreach (var element in elements)
            {
                try
                {
                    if (element is FamilyInstance && CheckElementPhase(element))
                    {
                        var revitElement = new RevitElement();
                        revitElement.Category = RevitCategory.Framing;
                        revitElement.Id       = element.Id.ToString();
                        revitElement.Name     = element.Name;

                        var   elementLevel = element.GetParameters("Reference Level");
                        Level levelElement = elementLevel.Count() > 0 ? a_doc.GetElement(elementLevel[0].AsElementId()) as Level : null;
                        revitElement.AssociatedLevel     = levelElement != null ? levelElement.Name : a_unknownLevelName;
                        revitElement.AssociatedElevation = levelElement != null ? levelElement.ProjectElevation : a_unknownLevelElevation;
                        revitElement.AssociatedLevel     = GetMappedLevel(revitElement.AssociatedLevel);

                        var elementVolume = element.GetParameters("Volume");
                        revitElement.Volume = elementVolume.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(elementVolume[0].AsDouble(), DisplayUnitType.DUT_CUBIC_FEET) : 0.0;
                        var framingStructuralMaterial = this.GetStructuralMaterialFromElement(element, a_doc);
                        revitElement.MaterialName = framingStructuralMaterial != null ? framingStructuralMaterial.Name : "";
                        revitElement.Material     = framingStructuralMaterial != null?GetMaterialType(framingStructuralMaterial) : MaterialType.Unknown;

                        double density = framingStructuralMaterial != null?GetDensity(framingStructuralMaterial) : 0.0;

                        revitElement.Density = density;

                        a_revitElementData.Add(revitElement);
                    }
                }
                catch (Exception e)
                {
                    ShowElementErrorMessage(element, e);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Read all BuiltInCategory.OST_StructuralFoundation elements from a Revit model.
        /// </summary>
        private void ReadFoundations()
        {
            var collector = new FilteredElementCollector(a_doc);
            List <ElementFilter> filters    = new List <ElementFilter>();
            var filterCategory              = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFoundation);
            var filterNotSymbol             = new ElementClassFilter(typeof(FamilySymbol), true);
            var filterNotFloorType          = new ElementClassFilter(typeof(FloorType), true);
            var filterNotWallFoundationType = new ElementClassFilter(typeof(WallFoundationType), true);

            filters.Add(filterCategory);
            filters.Add(filterNotSymbol);
            filters.Add(filterNotFloorType);
            filters.Add(filterNotWallFoundationType);
            var filter   = new LogicalAndFilter(filters);
            var elements = collector.WherePasses(filter).ToElements();

            foreach (var element in elements)
            {
                try
                {
                    if ((element is FamilyInstance || element is WallFoundation || element is Floor) && CheckElementPhase(element))
                    {
                        var revitElement = new RevitElement();
                        revitElement.Category = RevitCategory.Foundation;
                        revitElement.Id       = element.Id.ToString();
                        revitElement.Name     = element.Name;

                        IList <Parameter> level = null;
                        if (element is WallFoundation)
                        {
                            var wallFoundation      = element as WallFoundation;
                            var wallElement         = a_doc.GetElement(wallFoundation.WallId);
                            var temp                = wallElement.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
                            IList <Parameter> first = new List <Parameter>();
                            if (temp != null)
                            {
                                first.Add(temp);
                            }
                            level = first;
                        }
                        else
                        {
                            level = element.GetParameters("Level");
                        }
                        Level levelElement = level.Count() > 0 ? a_doc.GetElement(level[0].AsElementId()) as Level : null;
                        revitElement.AssociatedLevel     = levelElement != null ? levelElement.Name : a_unknownLevelName;
                        revitElement.AssociatedElevation = levelElement != null ? levelElement.ProjectElevation : a_unknownLevelElevation;
                        revitElement.AssociatedLevel     = GetMappedLevel(revitElement.AssociatedLevel);

                        var elementVolume = element.GetParameters("Volume");
                        revitElement.Volume = elementVolume.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(elementVolume[0].AsDouble(), DisplayUnitType.DUT_CUBIC_FEET) : 0.0;
                        var framingStructuralMaterial = this.GetStructuralMaterialFromElement(element, a_doc);
                        revitElement.MaterialName = framingStructuralMaterial != null ? framingStructuralMaterial.Name : "";
                        revitElement.Material     = framingStructuralMaterial != null?GetMaterialType(framingStructuralMaterial) : MaterialType.Unknown;

                        double density = framingStructuralMaterial != null?GetDensity(framingStructuralMaterial) : 0.0;

                        revitElement.Density = density;

                        a_revitElementData.Add(revitElement);
                    }
                }
                catch (Exception e)
                {
                    ShowElementErrorMessage(element, e);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Read all BuiltInCategory.OST_Walls elements from a Revit model.
        /// </summary>
        private void ReadWalls()
        {
            var collector = new FilteredElementCollector(a_doc);
            List <ElementFilter> filters = new List <ElementFilter>();
            var filterCategory           = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
            var filterNotSymbol          = new ElementClassFilter(typeof(FamilySymbol), true);
            var filterNotWallType        = new ElementClassFilter(typeof(WallType), true);

            filters.Add(filterCategory);
            filters.Add(filterNotSymbol);
            filters.Add(filterNotWallType);
            var filter   = new LogicalAndFilter(filters);
            var elements = collector.WherePasses(filter).ToElements();

            foreach (var element in elements)
            {
                try
                {
                    if (element is Wall && CheckElementPhase(element))
                    {
                        var revitElement = new RevitElement();
                        revitElement.Category = RevitCategory.Wall;
                        revitElement.Id       = element.Id.ToString();
                        revitElement.Name     = element.Name;

                        var   wallBaseConstraintParam = element.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
                        Level wallBaseConstraintLevel = wallBaseConstraintParam != null?a_doc.GetElement(wallBaseConstraintParam.AsElementId()) as Level : null;

                        revitElement.AssociatedLevel     = wallBaseConstraintLevel != null ? wallBaseConstraintLevel.Name : a_unknownLevelName;
                        revitElement.AssociatedElevation = wallBaseConstraintLevel != null ? wallBaseConstraintLevel.ProjectElevation : a_unknownLevelElevation;
                        revitElement.AssociatedLevel     = GetMappedLevel(revitElement.AssociatedLevel);

                        var elementVolume = element.GetParameters("Volume");
                        revitElement.Volume = elementVolume.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(elementVolume[0].AsDouble(), DisplayUnitType.DUT_CUBIC_FEET) : 0.0;
                        var framingStructuralMaterial = this.GetStructuralMaterialFromElement(element, a_doc);
                        revitElement.MaterialName = framingStructuralMaterial != null ? framingStructuralMaterial.Name : "";
                        revitElement.Material     = framingStructuralMaterial != null?GetMaterialType(framingStructuralMaterial) : MaterialType.Unknown;

                        double density = framingStructuralMaterial != null?GetDensity(framingStructuralMaterial) : 0.0;

                        revitElement.Density = density;

                        // Split Wall by Levels
                        var    unconnectedHeight = element.GetParameters("Unconnected Height"); // accounts for walls that have no top constraint assigned
                        double wallHeight        = unconnectedHeight.Count > 0 ? UnitUtils.ConvertFromInternalUnits(unconnectedHeight[0].AsDouble(), DisplayUnitType.DUT_DECIMAL_FEET) : 0;
                        if (wallBaseConstraintLevel != null && wallHeight > 0 && a_levelData.Count > 0)
                        {
                            var wallBottomElevation = wallBaseConstraintLevel.ProjectElevation;

                            var    wallBottomOffset = element.GetParameters("Base Offset");
                            var    baseOffset       = wallBottomOffset.Count > 0 ? UnitUtils.ConvertFromInternalUnits(wallBottomOffset[0].AsDouble(), DisplayUnitType.DUT_DECIMAL_FEET) : 0;
                            double wtrueBel         = wallBottomElevation + baseOffset; // true bottom elevation of wall with model offset applied
                            double wtrueTel         = wtrueBel + wallHeight;            // true top elevation of wall
                            SplitByLevels(revitElement, wtrueBel, wtrueTel, wallHeight);
                        }
                        else
                        {
                            a_revitElementData.Add(revitElement);
                        }
                    }
                }
                catch (Exception e)
                {
                    ShowElementErrorMessage(element, e);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Read all BuiltInCategory.OST_Floors elements from a Revit model.
        /// </summary>
        private void ReadFloors()
        {
            var collector = new FilteredElementCollector(a_doc);
            List <ElementFilter> filters = new List <ElementFilter>();
            var filterCategory           = new ElementCategoryFilter(BuiltInCategory.OST_Floors);
            var filterNotSymbol          = new ElementClassFilter(typeof(FamilySymbol), true);
            var filterNotFloorType       = new ElementClassFilter(typeof(FloorType), true);

            filters.Add(filterCategory);
            filters.Add(filterNotSymbol);
            filters.Add(filterNotFloorType);
            var filter   = new LogicalAndFilter(filters);
            var elements = collector.WherePasses(filter).ToElements();

            foreach (var element in elements)
            {
                try
                {
                    if (element is Floor && CheckElementPhase(element))
                    {
                        Floor floor        = element as Floor;
                        var   revitElement = new RevitElement();
                        revitElement.Category = RevitCategory.Floor;
                        revitElement.Id       = element.Id.ToString();
                        revitElement.Name     = element.Name;

                        var   floorLevelid = floor.LevelId;
                        Level levelElement = a_doc.GetElement(floorLevelid) as Level;
                        revitElement.AssociatedLevel     = levelElement != null ? levelElement.Name : a_unknownLevelName;
                        revitElement.AssociatedElevation = levelElement != null ? levelElement.ProjectElevation : a_unknownLevelElevation;
                        revitElement.AssociatedLevel     = GetMappedLevel(revitElement.AssociatedLevel);

                        var floorArea = element.GetParameters("Area");
                        revitElement.Area = floorArea.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(floorArea[0].AsDouble(), DisplayUnitType.DUT_SQUARE_FEET) : 0.0;

                        var elementVolume = element.GetParameters("Volume");
                        revitElement.Volume = elementVolume.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(elementVolume[0].AsDouble(), DisplayUnitType.DUT_CUBIC_FEET) : 0.0;

                        // Look for metal deck
                        bool addRevitElement = true;
                        var  floorTypeId     = element.GetTypeId();
                        var  floorType       = a_doc.GetElement(floorTypeId) as HostObjAttributes;
                        if (floorType != null)
                        {
                            var  elementCompoundStructure = floorType.GetCompoundStructure();
                            int  structuralLayerIndex     = elementCompoundStructure.StructuralMaterialIndex;
                            var  compoundStructureLayers  = elementCompoundStructure.GetLayers();
                            bool allStructuralDecks       = true;
                            for (int i = 0; i < compoundStructureLayers.Count; i++)
                            {
                                var elementLayer = compoundStructureLayers[i];
                                if (elementLayer.Function == MaterialFunctionAssignment.StructuralDeck)
                                {
                                    var elementLayerDeck     = a_doc.GetElement(elementLayer.DeckProfileId) as FamilySymbol;
                                    var elementLayerMaterial = a_doc.GetElement(elementLayer.MaterialId) as Material;
                                    if (elementLayerDeck != null && elementLayerMaterial != null)
                                    {
                                        // hr = height of rib
                                        var    hrParam = elementLayerDeck.GetParameters("hr");
                                        double hr      = hrParam.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(hrParam[0].AsDouble(), DisplayUnitType.DUT_DECIMAL_FEET) : 0.0;
                                        // wr = width of rib
                                        var    wrParam = elementLayerDeck.GetParameters("wr");
                                        double wr      = wrParam.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(wrParam[0].AsDouble(), DisplayUnitType.DUT_DECIMAL_FEET) : 0.0;
                                        // rr = root of rib
                                        var    rrParam = elementLayerDeck.GetParameters("rr");
                                        double rr      = rrParam.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(rrParam[0].AsDouble(), DisplayUnitType.DUT_DECIMAL_FEET) : 0.0;
                                        // Sr = width of rib
                                        var    srParam = elementLayerDeck.GetParameters("Sr");
                                        double Sr      = srParam.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(srParam[0].AsDouble(), DisplayUnitType.DUT_DECIMAL_FEET) : 0.0;
                                        // Thickness
                                        var    thicknessParam = elementLayerDeck.GetParameters("Thickness");
                                        double thickness      = thicknessParam.Count() > 0 ? UnitUtils.ConvertFromInternalUnits(thicknessParam[0].AsDouble(), DisplayUnitType.DUT_DECIMAL_FEET) : 0.0;
                                        // Layer Density
                                        double layerDensity = GetDensity(elementLayerMaterial);

                                        if (revitElement.Area > 0 &&
                                            Sr > 0 && hr > 0 && wr > 0 && rr > 0 && thickness > 0 && layerDensity > 0)
                                        {
                                            revitElement.Volume = revitElement.Volume - (revitElement.Area * hr / 2);

                                            double flange           = Sr - wr;
                                            double rib              = rr;
                                            double web              = Math.Sqrt(Math.Pow(hr, 2) + Math.Pow(((wr - rr) / 2), 2));
                                            double deckWidthFlatten = flange + rib + (2 * web);

                                            double weightOfOneFootOfDeck = deckWidthFlatten * thickness * 1 * layerDensity;
                                            double deckPsf      = weightOfOneFootOfDeck / (Sr * 1);
                                            double weightOfDeck = revitElement.Area * deckPsf;
                                            double volumeOfDeck = weightOfDeck / layerDensity;

                                            string       deckName  = elementLayerDeck.FamilyName + " - " + elementLayerDeck.Name;
                                            RevitElement floorDeck = new RevitElement(
                                                revitElement.Category, revitElement.Id, deckName, revitElement.AssociatedLevel, revitElement.AssociatedElevation, volumeOfDeck,
                                                elementLayerMaterial.Name, GetMaterialType(elementLayerMaterial), layerDensity);
                                            a_revitElementData.Add(floorDeck);

                                            // Don't add revitElement if added here, avoid double counting and counting deck with full depth volume.
                                            if (addRevitElement == true)
                                            {
                                                addRevitElement = structuralLayerIndex == i ? false : true;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    allStructuralDecks = false;
                                }
                            }

                            if (allStructuralDecks == false && addRevitElement == false)
                            {
                                addRevitElement = true;
                            }
                        }

                        var framingStructuralMaterial = this.GetStructuralMaterialFromElement(element, a_doc);
                        revitElement.MaterialName = framingStructuralMaterial != null ? framingStructuralMaterial.Name : "";
                        revitElement.Material     = framingStructuralMaterial != null?GetMaterialType(framingStructuralMaterial) : MaterialType.Unknown;

                        double density = framingStructuralMaterial != null?GetDensity(framingStructuralMaterial) : 0.0;

                        revitElement.Density = density;

                        if (addRevitElement)
                        {
                            a_revitElementData.Add(revitElement);
                        }
                    }
                }
                catch (Exception e)
                {
                    ShowElementErrorMessage(element, e);
                }
            }
        }