/***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static StructuralMaterialType StructuralMaterialType(this string materialClass)
        {
            if (string.IsNullOrEmpty(materialClass))
            {
                return(Autodesk.Revit.DB.Structure.StructuralMaterialType.Undefined);
            }

            StructuralMaterialType structuralMaterialType = Autodesk.Revit.DB.Structure.StructuralMaterialType.Undefined;

            if (Enum.TryParse(materialClass, out structuralMaterialType))
            {
                return(structuralMaterialType);
            }

            string matClass = materialClass.ToLower().Trim();

            switch (matClass)
            {
            case "aluminium":
                return(Autodesk.Revit.DB.Structure.StructuralMaterialType.Aluminum);

            case "concrete":
                return(Autodesk.Revit.DB.Structure.StructuralMaterialType.Concrete);

            case "steel":
            case "metal":
                return(Autodesk.Revit.DB.Structure.StructuralMaterialType.Steel);

            case "wood":
                return(Autodesk.Revit.DB.Structure.StructuralMaterialType.Wood);
            }

            return(Autodesk.Revit.DB.Structure.StructuralMaterialType.Undefined);
        }
Exemple #2
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static IMaterialFragment LibraryMaterial(this StructuralMaterialType structuralMaterialType, string materialGrade)
        {
            if (string.IsNullOrWhiteSpace(materialGrade))
            {
                return(null);
            }

            switch (structuralMaterialType)
            {
            case Autodesk.Revit.DB.Structure.StructuralMaterialType.PrecastConcrete:
            case Autodesk.Revit.DB.Structure.StructuralMaterialType.Concrete:
                foreach (IBHoMObject concrete in BH.Engine.Library.Query.Library("Materials").Where(x => x is Concrete))
                {
                    if (materialGrade.Contains(concrete.Name))
                    {
                        return(concrete as IMaterialFragment);
                    }
                }
                break;

            case Autodesk.Revit.DB.Structure.StructuralMaterialType.Steel:
                foreach (IBHoMObject steel in BH.Engine.Library.Query.Library("Materials").Where(x => x is Steel))
                {
                    if (materialGrade.Contains(steel.Name))
                    {
                        return(steel as IMaterialFragment);
                    }
                }
                break;

            case Autodesk.Revit.DB.Structure.StructuralMaterialType.Aluminum:
                foreach (IBHoMObject aluminium in BH.Engine.Library.Query.Library("Materials").Where(x => x is Aluminium))
                {
                    if (materialGrade.Contains(aluminium.Name))
                    {
                        return(aluminium as IMaterialFragment);
                    }
                }
                break;

            case Autodesk.Revit.DB.Structure.StructuralMaterialType.Wood:
                foreach (IBHoMObject timber in BH.Engine.Library.Query.Library("Materials").Where(x => x is Timber))
                {
                    if (materialGrade.Contains(timber.Name))
                    {
                        return(timber as IMaterialFragment);
                    }
                }
                break;
            }

            return(null);
        }
Exemple #3
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static IMaterialFragment EmptyMaterialFragment(this StructuralMaterialType structuralMaterialType, string grade)
        {
            string name;

            if (structuralMaterialType == Autodesk.Revit.DB.Structure.StructuralMaterialType.Undefined)
            {
                name = "Unknown Material";
            }
            else
            {
                name = String.Format("Unknown {0} Material", structuralMaterialType);
            }

            if (!string.IsNullOrWhiteSpace(grade))
            {
                name += " grade " + grade;
            }

            switch (structuralMaterialType)
            {
            case Autodesk.Revit.DB.Structure.StructuralMaterialType.Aluminum:
                return(new Aluminium()
                {
                    Name = name
                });

            case Autodesk.Revit.DB.Structure.StructuralMaterialType.Concrete:
            case Autodesk.Revit.DB.Structure.StructuralMaterialType.PrecastConcrete:
                return(new Concrete()
                {
                    Name = name
                });

            case Autodesk.Revit.DB.Structure.StructuralMaterialType.Wood:
                return(new Timber()
                {
                    Name = name
                });

            case Autodesk.Revit.DB.Structure.StructuralMaterialType.Steel:
                return(new Steel()
                {
                    Name = name
                });

            default:
                return(new GenericIsotropicMaterial()
                {
                    Name = name
                });
            }
        }
        /***************************************************/

        internal static void NotConvertedWarning(this StructuralMaterialType structuralMaterialType)
        {
            BH.Engine.Reflection.Compute.RecordWarning("Structural material type " + structuralMaterialType + " could not be converted because conversion method does not exist.");
        }
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static IMaterialFragment MaterialFragmentFromRevit(this Material material, string grade = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            if (material == null)
            {
                return(null);
            }

            string            refId            = material.Id.ReferenceIdentifier(grade);
            IMaterialFragment materialFragment = refObjects.GetValue <IMaterialFragment>(refId);

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

            settings = settings.DefaultIfNull();

            StructuralMaterialType structuralMaterialType = material.MaterialClass.StructuralMaterialType();

            materialFragment = structuralMaterialType.LibraryMaterial(grade);
            if (materialFragment != null)
            {
                return(materialFragment);
            }

            Compute.MaterialNotInLibraryNote(material);

            switch (structuralMaterialType)
            {
            case StructuralMaterialType.Concrete:
            case StructuralMaterialType.PrecastConcrete:
                materialFragment = new Concrete();
                break;

            case StructuralMaterialType.Aluminum:
                materialFragment = new Aluminium();
                break;

            case StructuralMaterialType.Steel:
                materialFragment = new Steel();
                break;

            case StructuralMaterialType.Wood:
                materialFragment = new Timber();
                break;

            default:
                BH.Engine.Reflection.Compute.RecordWarning(String.Format("Revit material of structural type {0} is currently not supported, the material was converted to a generic isotropic BHoM material. Revit ElementId: {1}", structuralMaterialType, material.Id.IntegerValue));
                materialFragment = new GenericIsotropicMaterial();
                break;
            }

            materialFragment.CopyCharacteristics(material);

            string name = material.Name;

            if (!string.IsNullOrWhiteSpace(grade))
            {
                name += " grade " + grade;
            }

            materialFragment.Name = name;

            refObjects.AddOrReplace(refId, materialFragment);
            return(materialFragment);
        }