Пример #1
0
        /***************************************************/

        private static ISectionProperty ToSectionProperty(BHP.FramingProperties.ConstantFramingProperty property)
        {
            BHP.Materials.Material material = property.Material;

            IMaterialFragment fragment;

            if (material == null)
            {
                Reflection.Compute.RecordError("The FramingElement does not contain any material. An empty generic isotropic material has been used");
                fragment = new GenericIsotropicMaterial();
            }
            else if (!material.IsValidStructural())
            {
                string matName = material.Name ?? "";
                Reflection.Compute.RecordWarning("The material with name " + matName + " is not a valid structural material as it does not contain exactly one structural material fragment. An empty generic isotropic material has been assumed");
                fragment = new GenericIsotropicMaterial {
                    Name = matName
                };
            }
            else
            {
                fragment = material.StructuralMaterialFragment();
            }

            return(Create.SectionPropertyFromProfile(property.Profile, fragment, property.Name));
        }
        public static ConstantFramingProperty ConstantFramingProperty(ISectionProperty sectionProperty, double orientationAngle, string name = "")
        {
            IProfile profile = null;

            if (sectionProperty is IGeometricalSection)
            {
                profile = (sectionProperty as IGeometricalSection).SectionProfile;
            }
            else
            {
                Reflection.Compute.RecordWarning("Was not able to extract any section profile.");
            }


            BH.oM.Physical.Materials.Material material = null;

            if (sectionProperty.Material != null)
            {
                string matName = sectionProperty.Material.Name ?? "";
                material = Physical.Create.Material(matName, new List <oM.Physical.Materials.IMaterialProperties> {
                    sectionProperty.Material
                });
            }
            else
            {
                Engine.Reflection.Compute.RecordWarning("Material from sectiion property of the bar is null.");
            }

            name = string.IsNullOrEmpty(name) ? sectionProperty.Name : name;

            return(Physical.Create.ConstantFramingProperty(profile, material, orientationAngle, name));
        }
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static IFramingElementProperty FramingElementProperty(this FamilyInstance familyInstance, RevitSettings settings, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            if (familyInstance == null || familyInstance.Symbol == null)
            {
                return(null);
            }

            ConstantFramingProperty framingProperty = refObjects.GetValue <ConstantFramingProperty>(familyInstance.Id);

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

            // Convert the material to BHoM.
            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;
            }

            string materialGrade = familyInstance.MaterialGrade(settings);

            BH.oM.Physical.Materials.Material material = revitMaterial.MaterialFromRevit(materialGrade, settings, refObjects);

            // If Revit material is null, rename the BHoM material based on material type of framing family.
            if (material != null && revitMaterial == null)
            {
                material.Name = String.Format("Unknown {0} Material", familyInstance.StructuralMaterialType);
                material.Properties.Add(familyInstance.StructuralMaterialType.EmptyMaterialFragment(materialGrade));
            }

            IProfile profile = familyInstance.Symbol.ProfileFromRevit(settings, refObjects);

            if (profile == null)
            {
                familyInstance.Symbol.NotConvertedWarning();
            }

            double rotation = familyInstance.OrientationAngle(settings);

            framingProperty = BH.Engine.Physical.Create.ConstantFramingProperty(profile, material, rotation, familyInstance.Symbol.Name);

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

            refObjects.AddOrReplace(familyInstance.Id, framingProperty);
            return(framingProperty);
        }
Пример #4
0
        /***************************************************/

        private static ISectionProperty ToSectionProperty(BHP.FramingProperties.ConstantFramingProperty property)
        {
            ISectionProperty prop = null;

            BHP.Materials.Material material = property.Material;

            IMaterialFragment fragment;

            if (material == null)
            {
                Reflection.Compute.RecordError("The FramingElement does not contain any material. An empty steel material has been used");
                fragment = new Steel();
            }
            else if (!material.IsValidStructural())
            {
                string matName = material.Name ?? "";
                Reflection.Compute.RecordWarning("The material with name " + matName + " is not a valid structural material as it does not contain exactly one structural material fragment. An empty steel material has been assumed");
                fragment = new Steel {
                    Name = matName
                };
            }
            else
            {
                fragment = material.StructuralMaterialFragment();
            }

            switch (fragment.IMaterialType())
            {
            case oM.Structure.MaterialFragments.MaterialType.Steel:
                prop = Create.SteelSectionFromProfile(property.Profile, fragment as Steel, property.Name);
                break;

            case oM.Structure.MaterialFragments.MaterialType.Concrete:
                prop = Create.ConcreteSectionFromProfile(property.Profile, fragment as Concrete, property.Name);
                break;

            case oM.Structure.MaterialFragments.MaterialType.Aluminium:
            case oM.Structure.MaterialFragments.MaterialType.Timber:
            case oM.Structure.MaterialFragments.MaterialType.Rebar:
            case oM.Structure.MaterialFragments.MaterialType.Tendon:
            case oM.Structure.MaterialFragments.MaterialType.Glass:
            case oM.Structure.MaterialFragments.MaterialType.Cable:
            case oM.Structure.MaterialFragments.MaterialType.Undefined:
            default:
                prop          = Create.SteelSectionFromProfile(property.Profile, null, property.Name);
                prop.Material = fragment;
                Reflection.Compute.RecordWarning("The BHoM does not currently support sections of material type " + fragment.IMaterialType() + ". A steel section has been created with the material applied to it");
                break;
            }

            return(prop);
        }
Пример #5
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static RevitMaterialTakeOff MaterialTakeoff(this Element element, RevitSettings settings, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            Dictionary <BH.oM.Physical.Materials.Material, double> takeoff = new Dictionary <BH.oM.Physical.Materials.Material, double>();
            double totalVolume = 0;
            string grade       = element.MaterialGrade(settings);

            foreach (ElementId materialId in element.GetMaterialIds(false))
            {
                double volume = element.GetMaterialVolume(materialId).ToSI(UnitType.UT_Volume);
                if (volume <= settings.DistanceTolerance)
                {
                    continue;
                }

                Material material = (Material)element.Document.GetElement(materialId);
                BH.oM.Physical.Materials.Material bHoMMaterial = material.MaterialFromRevit(grade, settings, refObjects);
                if (takeoff.ContainsKey(bHoMMaterial))
                {
                    takeoff[bHoMMaterial] += volume;
                }
                else
                {
                    takeoff[bHoMMaterial] = volume;
                }

                totalVolume += volume;
            }

            if (takeoff.Count != 0)
            {
                return(new RevitMaterialTakeOff(totalVolume, new oM.Physical.Materials.MaterialComposition(takeoff.Keys, takeoff.Values.Select(x => x / totalVolume))));
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        /***************************************************/

        public static bool Update(this Material element, BH.oM.Physical.Materials.Material bHoMObject, RevitSettings settings, bool setLocationOnUpdate)
        {
            foreach (BH.oM.Physical.Materials.IMaterialProperties property in bHoMObject.Properties)
            {
                element.ICopyCharacteristics(property);
            }

            element.CopyParameters(bHoMObject, settings);

            if (!string.IsNullOrWhiteSpace(bHoMObject.Name) && element.Name != bHoMObject.Name)
            {
                try
                {
                    element.Name = bHoMObject.Name;
                }
                catch
                {
                }
            }

            return(true);
        }
Пример #7
0
        /***************************************************/

        public static Element ToRevit(this BH.oM.Physical.Materials.Material material, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            return(material.ToRevitMaterial(document, settings, refObjects));
        }
Пример #8
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static IFramingElementProperty FramingElementProperty(this FamilyInstance familyInstance, RevitSettings settings, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            if (familyInstance == null || familyInstance.Symbol == null)
            {
                return(null);
            }

            ConstantFramingProperty framingProperty = refObjects.GetValue <ConstantFramingProperty>(familyInstance.Id);

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

            // Convert the material to BHoM.
            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;
            }

            string materialGrade = familyInstance.MaterialGrade(settings);

            BH.oM.Physical.Materials.Material material = revitMaterial.MaterialFromRevit(materialGrade, settings, refObjects);

            // If Revit material is null, rename the BHoM material based on material type of framing family.
            if (material != null && revitMaterial == null)
            {
                material.Name = String.Format("Unknown {0} Material", familyInstance.StructuralMaterialType);
                material.Properties.Add(familyInstance.StructuralMaterialType.EmptyMaterialFragment(materialGrade));
            }

            IProfile profile = familyInstance.Symbol.ProfileFromRevit(settings, refObjects);

            if (profile == null)
            {
                familyInstance.Symbol.NotConvertedWarning();
            }

            if (familyInstance.Mirrored)
            {
                if (profile is FreeFormProfile)
                {
                    BH.oM.Geometry.Plane mirror = new oM.Geometry.Plane {
                        Normal = BH.oM.Geometry.Vector.XAxis
                    };
                    profile = BH.Engine.Spatial.Create.FreeFormProfile(profile.Edges.Select(x => x.IMirror(mirror)));
                }
                else if (profile is AngleProfile)
                {
                    AngleProfile angle = ((AngleProfile)profile);
                    profile = BH.Engine.Spatial.Create.AngleProfile(angle.Height, angle.Width, angle.WebThickness, angle.FlangeThickness, angle.RootRadius, angle.ToeRadius, true, false);
                }
                else if (profile is ChannelProfile)
                {
                    ChannelProfile channel = ((ChannelProfile)profile);
                    profile = BH.Engine.Spatial.Create.ChannelProfile(channel.Height, channel.FlangeWidth, channel.WebThickness, channel.FlangeThickness, channel.RootRadius, channel.ToeRadius, true);
                }
            }

            double rotation = familyInstance.OrientationAngle(settings);

            framingProperty = BH.Engine.Physical.Create.ConstantFramingProperty(profile, material, rotation, familyInstance.Symbol.Name);

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

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