Beispiel #1
0
        /***************************************************/
        /****             Interface Methods             ****/
        /***************************************************/

        public static oM.Geometry.ICurve IFromRevit(this Curve curve)
        {
            oM.Geometry.ICurve result = FromRevit(curve as dynamic);

            if (result == null)
            {
                BH.Engine.Reflection.Compute.RecordWarning("Curve types without conversion support have been tessellated and converted into Polylines.");

                IList <XYZ> xyzList = curve.Tessellate();
                if (xyzList == null || xyzList.Count < 2)
                {
                    result = null;
                }
                else
                {
                    result = new BH.oM.Geometry.Polyline {
                        ControlPoints = xyzList.Select(x => x.PointFromRevit()).ToList()
                    }
                };
            }

            return(result);
        }

        /***************************************************/
    }
Beispiel #2
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static oM.Geometry.PlanarSurface FromRevit(this PlanarFace face)
        {
            if (face == null)
            {
                return(null);
            }

            IList <CurveLoop> crvLoop = face.GetEdgesAsCurveLoops();

            oM.Geometry.ICurve        externalBoundary = crvLoop[0].FromRevit();
            List <oM.Geometry.ICurve> internalBoundary = crvLoop.Skip(1).Select(x => x.FromRevit() as oM.Geometry.ICurve).ToList();

            return(new oM.Geometry.PlanarSurface(externalBoundary, internalBoundary));
        }
Beispiel #3
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static Column ColumnFromRevit(this FamilyInstance familyInstance, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            Column column = refObjects.GetValue <Column>(familyInstance.Id);

            if (column != null)
            {
                return(column);
            }

            oM.Geometry.ICurve      locationCurve = familyInstance.LocationCurveColumn(settings);
            IFramingElementProperty property      = familyInstance.FramingElementProperty(settings, refObjects);

            column = BH.Engine.Physical.Create.Column(locationCurve, property, familyInstance.Name);

            //Set identifiers, parameters & custom data
            column.SetIdentifiers(familyInstance);
            column.CopyParameters(familyInstance, settings.ParameterSettings);
            column.SetProperties(familyInstance, settings.ParameterSettings);

            refObjects.AddOrReplace(familyInstance.Id, column);
            return(column);
        }
Beispiel #4
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static Beam BeamFromRevit(this FamilyInstance familyInstance, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            Beam beam = refObjects.GetValue <Beam>(familyInstance.Id);

            if (beam != null)
            {
                return(beam);
            }

            oM.Geometry.ICurve      locationCurve = familyInstance.LocationCurveFraming(settings);
            IFramingElementProperty property      = familyInstance.FramingElementProperty(settings, refObjects);

            beam = BH.Engine.Physical.Create.Beam(locationCurve, property, familyInstance.Name);

            //Set identifiers, parameters & custom data
            beam.SetIdentifiers(familyInstance);
            beam.CopyParameters(familyInstance, settings.ParameterSettings);
            beam.SetProperties(familyInstance, settings.ParameterSettings);

            refObjects.AddOrReplace(familyInstance.Id, beam);
            return(beam);
        }
Beispiel #5
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static List <Bar> BarsFromRevit(this FamilyInstance familyInstance, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            List <Bar> bars = refObjects.GetValues <Bar>(familyInstance.Id);

            if (bars != null)
            {
                return(bars);
            }

            // Get bar curve
            oM.Geometry.ICurve   locationCurve   = null;
            AnalyticalModelStick analyticalModel = familyInstance.GetAnalyticalModel() as AnalyticalModelStick;

            if (analyticalModel != null)
            {
                Curve curve = analyticalModel.GetCurve();
                if (curve != null)
                {
                    locationCurve = curve.IFromRevit();
                }
            }

            if (locationCurve != null)
            {
                familyInstance.AnalyticalPullWarning();
            }
            else
            {
                locationCurve = familyInstance.LocationCurve(settings);
            }

            // Get bar material
            ElementId structuralMaterialId = familyInstance.StructuralMaterialId;

            if (structuralMaterialId.IntegerValue < 0)
            {
                structuralMaterialId = familyInstance.Symbol.LookupParameterElementId(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
            }

            Material revitMaterial = familyInstance.Document.GetElement(structuralMaterialId) as Material;

            if (revitMaterial == null)
            {
                revitMaterial = familyInstance.Category.Material;
            }

            // Get material grade
            string materialGrade = familyInstance.MaterialGrade(settings);

            // Find material fragment: convert the material assigned to the element, if that returns null try finding a material in the library, based on the material type assigned to the family.
            IMaterialFragment materialFragment = revitMaterial.MaterialFragmentFromRevit(materialGrade, settings, refObjects);

            if (materialFragment == null)
            {
                materialFragment = familyInstance.StructuralMaterialType.LibraryMaterial(materialGrade);
            }

            // If material fragment could not be found create an empty one and raise a warning further down the line.
            bool materialFound = materialFragment != null;

            if (materialFragment == null)
            {
                materialFragment = familyInstance.StructuralMaterialType.EmptyMaterialFragment(materialGrade);
            }

            // Get bar profile and create property
            string           profileName = familyInstance.Symbol.Name;
            ISectionProperty property    = BH.Engine.Library.Query.Match("SectionProperties", profileName) as ISectionProperty;

            if (property == null)
            {
                IProfile profile = familyInstance.Symbol.ProfileFromRevit(settings, refObjects);

                //TODO: this should be removed and null passed finally?
                if (profile == null)
                {
                    profile = new FreeFormProfile(new List <oM.Geometry.ICurve>());
                }

                if (profile.Edges.Count == 0)
                {
                    familyInstance.Symbol.ConvertProfileFailedWarning();
                }

                if (!materialFound)
                {
                    Compute.InvalidDataMaterialWarning(familyInstance);
                }

                property = BH.Engine.Structure.Create.SectionPropertyFromProfile(profile, materialFragment, profileName);
            }
            else
            {
                property = property.ShallowClone();

                if (!materialFound)
                {
                    BH.Engine.Reflection.Compute.RecordNote($"A matching section was found in the library. No valid material was defined in Revit, so the default material for this section was used. Revit ElementId: {familyInstance.Id.IntegerValue}");
                }
                else
                {
                    property.Material = materialFragment;
                }

                property.Name = profileName;
            }

            // Create linear bars
            bars = new List <Bar>();
            if (locationCurve != null)
            {
                //TODO: check category of familyInstance to recognize which rotation query to use
                double rotation = familyInstance.OrientationAngle(settings);
                foreach (BH.oM.Geometry.Line line in locationCurve.ICollapseToPolyline(Math.PI / 12).SubParts())
                {
                    bars.Add(BH.Engine.Structure.Create.Bar(line, property, rotation));
                }
            }
            else
            {
                bars.Add(BH.Engine.Structure.Create.Bar(null, null, property, 0));
            }

            for (int i = 0; i < bars.Count; i++)
            {
                bars[i].Name = familyInstance.Name;

                //Set identifiers, parameters & custom data
                bars[i].SetIdentifiers(familyInstance);
                bars[i].CopyParameters(familyInstance, settings.ParameterSettings);
                bars[i].SetProperties(familyInstance, settings.ParameterSettings);
            }

            refObjects.AddOrReplace(familyInstance.Id, bars);
            return(bars);
        }