コード例 #1
0
 /// <summary>
 /// Assignes a color-based material to all of the site-subregions
 /// </summary>
 /// <param name="color">Color to be assigned to the site sub-regions</param>
 public void AssignColor(Color color)
 {
     using (Transaction assignMaterial = new Transaction(_doc))
     {
         assignMaterial.Start();
         ElementId matId = Material.Create(_doc, "Subregion");
         Material  mat   = _doc.GetElement(matId) as Material;
         //Create a new property set that can be used by this material
         StructuralAsset strucAsset = new StructuralAsset("My Property Set", StructuralAssetClass.Concrete);
         strucAsset.Behavior = StructuralBehavior.Isotropic;
         strucAsset.Density  = 232.0;
         //Assign the property set to the material.
         PropertySetElement pse = PropertySetElement.Create(_doc, strucAsset);
         mat.SetMaterialAspectByPropertySet(MaterialAspect.Structural, pse.Id);
         mat.Color = color;
         for (int i = 0; i < this.SiteSubRegions.Count; i++)
         {
             foreach (Parameter prm in this.SiteSubRegions[i].TopographySurface.ParametersMap)
             {
                 if (prm.StorageType == StorageType.ElementId && prm.Definition.ParameterType == ParameterType.Material)
                 {
                     prm.Set(matId);
                 }
             }
         }
         assignMaterial.Commit();
     }
 }
コード例 #2
0
        /***************************************************/
        /****        Public methods - Materials         ****/
        /***************************************************/

        public static void CopyCharacteristics(this SolidMaterial toMaterial, Material fromMaterial)
        {
            if (fromMaterial == null)
            {
                toMaterial.NullRevitElementWarning();
                return;
            }

            ElementId elementID = fromMaterial.ThermalAssetId;

            if (elementID == null || elementID == ElementId.InvalidElementId)
            {
                toMaterial.NullThermalAssetWarning();
                return;
            }

            PropertySetElement propertySetElement = fromMaterial.Document.GetElement(elementID) as PropertySetElement;
            ThermalAsset       thermalAsset       = propertySetElement?.GetThermalAsset();

            if (thermalAsset == null)
            {
                Compute.NullThermalAssetWarning(toMaterial);
                return;
            }

            toMaterial.CopyCharacteristics(thermalAsset);
        }
コード例 #3
0
        /// <summary>
        /// Create a new brick material
        /// </summary>
        /// <returns>The specific material</returns>
        private Material CreateSampleBrickMaterial()
        {
            SubTransaction createMaterial = new SubTransaction(this.m_document.Document);

            createMaterial.Start();
            Material materialNew = null;

            //Try to copy an existing material.  If it is not available, create a new one.
            Material masonry_Brick = GetMaterial("Brick, Common");

            if (masonry_Brick != null)
            {
                materialNew = masonry_Brick.Duplicate(masonry_Brick.Name + "_new");
                System.Diagnostics.Debug.WriteLine(masonry_Brick.MaterialClass);
                materialNew.MaterialClass = "Brick";
            }
            else
            {
                ElementId idNew = Material.Create(m_document.Document, "New Brick Sample");
                materialNew       = m_document.Document.GetElement(idNew) as Material;
                materialNew.Color = new Autodesk.Revit.DB.Color(255, 0, 0);
            }
            createMaterial.Commit();

            SubTransaction createPropertySets = new SubTransaction(this.m_document.Document);

            createPropertySets.Start();

            //Create a new structural asset and set properties on it.
            StructuralAsset structuralAsssetBrick = new StructuralAsset("BrickStructuralAsset", Autodesk.Revit.DB.StructuralAssetClass.Generic);

            structuralAsssetBrick.DampingRatio = .5;

            PropertySetElement pseStructural = PropertySetElement.Create(m_document.Document, structuralAsssetBrick);


            //Create a new thermal asset and set properties on it.
            ThermalAsset thermalAssetBrick = new ThermalAsset("BrickThermalAsset", Autodesk.Revit.DB.ThermalMaterialType.Solid);

            thermalAssetBrick.Porosity            = 0.1;
            thermalAssetBrick.Permeability        = 0.2;
            thermalAssetBrick.Compressibility     = .5;
            thermalAssetBrick.ThermalConductivity = .5;

            //Create PropertySets from assets and assign them to the material.
            PropertySetElement pseThermal = PropertySetElement.Create(m_document.Document, thermalAssetBrick);

            createPropertySets.Commit();
            SubTransaction setPropertySets = new SubTransaction(this.m_document.Document);

            setPropertySets.Start();
            materialNew.SetMaterialAspectByPropertySet(MaterialAspect.Structural, pseStructural.Id);
            materialNew.SetMaterialAspectByPropertySet(MaterialAspect.Thermal, pseThermal.Id);

            //also try
            //materialNew.ThermalAssetId = pseThermal.Id;

            setPropertySets.Commit();
            return(materialNew);
        }
コード例 #4
0
        /***************************************************/

        public static void CopyCharacteristics(this IMaterialFragment toMaterial, Material fromMaterial)
        {
            if (fromMaterial == null)
            {
                toMaterial.NullRevitElementWarning();
                return;
            }

            ElementId elementID = fromMaterial.StructuralAssetId;

            if (elementID == null || elementID == ElementId.InvalidElementId)
            {
                toMaterial.NullStructuralAssetWarning();
                return;
            }

            PropertySetElement propertySetElement = fromMaterial.Document.GetElement(elementID) as PropertySetElement;
            StructuralAsset    structuralAsset    = propertySetElement?.GetStructuralAsset();

            if (structuralAsset == null)
            {
                Compute.NullStructuralAssetWarning(toMaterial);
                return;
            }

            toMaterial.CopyCharacteristics(structuralAsset);
        }
コード例 #5
0
 /// <summary>
 /// Get the material type via giving material.
 /// According to my knowledge, the material type can be retrieved by two ways now:
 /// 1. If the PropertySetElement exists, retrieve it by PHY_MATERIAL_PARAM_CLASS parameter. (via PropertySetElement class)
 /// 2. If it's indenpendent, retrieve it by PHY_MATERIAL_PARAM_TYPE parameter(via Material class)
 /// </summary>
 /// <param name="material"></param>
 /// <returns></returns>
 private StructuralAssetClass GetMaterialType(Material material)
 {
     if (material.StructuralAssetId != ElementId.InvalidElementId)
     {
         PropertySetElement propElem     = m_revit.ActiveUIDocument.Document.GetElement(material.StructuralAssetId) as PropertySetElement;
         Parameter          propElemPara = propElem.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS);
         if (propElemPara != null)
         {
             return((StructuralAssetClass)propElemPara.AsInteger());
         }
     }
     return(StructuralAssetClass.Undefined);
     //ElementId propElemId = material.GetMaterialAspectPropertySet(MaterialAspect.Structural);
     //if (ElementId.InvalidElementId == propElemId)
     //{
     //    Parameter independentPara = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_TYPE);
     //    if (null == independentPara)
     //    {
     //        return MaterialType.Generic;
     //    }
     //    return (MaterialType)independentPara.AsInteger();
     //}
     //PropertySetElement propElem = m_revit.ActiveUIDocument.Document.GetElement(propElemId) as PropertySetElement;
     //Parameter propElemPara = propElem.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS);
     //if (null == propElemPara)
     //{
     //    return MaterialType.Generic;
     //}
     //return (MaterialType)propElemPara.AsInteger();
 }
コード例 #6
0
        public static double GetMaterialDensity(Document doc, ElementId materialId)
        {
            Material material = doc.GetElement(materialId) as Material;

            if (material.StructuralAssetId == ElementId.InvalidElementId)
            {
                string msg = "Не заданы Физические свойства материала " + material.Name;
                System.Windows.Forms.MessageBox.Show(msg);
                throw new Exception(msg);
            }
            PropertySetElement materialStructuralParams = doc.GetElement(material.StructuralAssetId) as PropertySetElement;
            double             density = materialStructuralParams.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_STRUCTURAL_DENSITY).AsDouble();

            return(density);
        }
コード例 #7
0
        /// <summary>
        /// Getting the specific material by name.
        /// </summary>
        /// <param name="name">The name of specific material.</param>
        /// <returns>The specific material</returns>

        /*  public static Material GetMaterialfromlibray(string name, Autodesk.Revit.ApplicationServices.Application revitApp)
         * {
         *    FilteredElementCollector collector = new FilteredElementCollector(revitApp.Documents.);
         *    collector.WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_Materials));
         *    var MaterialElement = from element in collector
         *                          where element.Name == name
         *                          select element;
         *
         *    if (MaterialElement.Count() == 0)
         *        return null;
         *    return MaterialElement.First<Element>() as Material;
         * }*/
        /// <summary>
        /// Create a new brick material
        /// </summary>
        /// <returns>The specific material</returns>
        public static Material CreateSampleConcreteMaterial(UIDocument m_document)
        {
            Material materialNew = null;
            //Try to copy an existing material.  If it is not available, create a new one.
            Material masonry_Concrete = GetMaterial("Concrete, Lightweight", m_document);

            if (masonry_Concrete != null)
            {
                TaskDialog.Show("Tip", "找到这种材料了!");
                materialNew = masonry_Concrete.Duplicate(masonry_Concrete.Name + "_new");
                materialNew.MaterialClass = "Concrete";
            }
            else
            {
                ElementId idNew = Material.Create(m_document.Document, "New Concrete Sample");
                materialNew       = m_document.Document.GetElement(idNew) as Material;
                materialNew.Color = new Autodesk.Revit.DB.Color(130, 150, 120);
            }

            //创建外观属性

            //Create a new structural asset and set properties on it.
            StructuralAsset structuralAsssetConcrete = new StructuralAsset("ConcreteStructuralAsset", Autodesk.Revit.DB.StructuralAssetClass.Concrete);

            structuralAsssetConcrete.ConcreteBendingReinforcement = .5;
            structuralAsssetConcrete.DampingRatio = .5;

            //Create a new thermal asset and set properties on it.
            ThermalAsset thermalAssetConcrete = new ThermalAsset("ConcreteThermalAsset", Autodesk.Revit.DB.ThermalMaterialType.Solid);

            thermalAssetConcrete.Porosity            = 0.2;
            thermalAssetConcrete.Permeability        = 0.3;
            thermalAssetConcrete.Compressibility     = .5;
            thermalAssetConcrete.ThermalConductivity = .5;

            //Create PropertySets from assets and assign them to the material.
            PropertySetElement pseThermal    = PropertySetElement.Create(m_document.Document, thermalAssetConcrete);
            PropertySetElement pseStructural = PropertySetElement.Create(m_document.Document, structuralAsssetConcrete);

            materialNew.SetMaterialAspectByPropertySet(MaterialAspect.Structural, pseStructural.Id);
            materialNew.SetMaterialAspectByPropertySet(MaterialAspect.Thermal, pseThermal.Id);

            return(materialNew);
        }
コード例 #8
0
        void GetElementMaterialInfo(Document doc)
        {
            FilteredElementCollector collector
                = new FilteredElementCollector(doc)
                  .WhereElementIsNotElementType()
                  .OfClass(typeof(Material));

            try
            {
                foreach (Material material in collector)
                {
                    if (material.Name.Equals("Air"))
                    {
                        AppearanceAssetElement appearanceElement
                            = doc.GetElement(material.AppearanceAssetId)
                              as AppearanceAssetElement;

                        Asset appearanceAsset = appearanceElement
                                                .GetRenderingAsset();

                        List <AssetProperty> assetProperties
                            = new List <AssetProperty>();

                        PropertySetElement physicalPropSet
                            = doc.GetElement(material.StructuralAssetId)
                              as PropertySetElement;

                        PropertySetElement thermalPropSet
                            = doc.GetElement(material.ThermalAssetId)
                              as PropertySetElement;

                        ThermalAsset thermalAsset = thermalPropSet
                                                    .GetThermalAsset();

                        StructuralAsset physicalAsset = physicalPropSet
                                                        .GetStructuralAsset();

                        ICollection <Parameter> physicalParameters
                            = physicalPropSet.GetOrderedParameters();

                        ICollection <Parameter> thermalParameters
                            = thermalPropSet.GetOrderedParameters();

                        // Appearance Asset

                        for (int i = 0; i < appearanceAsset.Size; i++)
                        {
                            AssetProperty property = appearanceAsset[i];
                            assetProperties.Add(property);
                        }
                        foreach (AssetProperty assetProp in assetProperties)
                        {
                            Type   type           = assetProp.GetType();
                            object assetPropValue = null;
                            var    prop           = type.GetProperty("Value");
                            if (prop != null &&
                                prop.GetIndexParameters().Length == 0)
                            {
                                assetPropValue = prop.GetValue(assetProp);
                            }
                        }

                        // Physical (Structural) Asset

                        foreach (Parameter p in physicalParameters)
                        {
                            // Work with parameters here
                            // The only parameter not in the orderedParameters
                            // that is needed is the Asset name, which you
                            // can get by 'physicalAsset.Name'.
                        }

                        // Thermal Asset

                        foreach (Parameter p in thermalParameters)
                        {
                            //Work with parameters here
                            //The only parameter not in the orderedParameters
                            // that is needed is the Asset name, shich you
                            // can get by 'thermalAsset.Name'.
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #9
0
ファイル: Material.cs プロジェクト: HoareLea/SAM_Revit
        public static Material ToSAM(this Autodesk.Revit.DB.Material material, ConvertSettings convertSettings)
        {
            if (material == null)
            {
                return(null);
            }

            Material result = convertSettings?.GetObject <Material>(material.Id);

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

            Document document = material.Document;

            double density             = double.NaN;
            double thermalConductivity = double.NaN;
            ThermalMaterialType thermalMaterialType = ThermalMaterialType.Undefined;
            bool transmitsLight = false;

            ElementId elementId = material.ThermalAssetId;

            if (elementId != null && elementId != ElementId.InvalidElementId)
            {
                PropertySetElement propertySetElement = document.GetElement(elementId) as PropertySetElement;
                if (propertySetElement != null)
                {
                    ThermalAsset thermalAsset = propertySetElement.GetThermalAsset();
                    if (thermalAsset != null)
                    {
                        density             = thermalAsset.Density;
                        thermalConductivity = thermalAsset.ThermalConductivity;
                        thermalMaterialType = thermalAsset.ThermalMaterialType;
                        transmitsLight      = thermalAsset.TransmitsLight;
                    }
                }
            }

            string description = material.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION)?.AsString();

            if (thermalMaterialType != ThermalMaterialType.Undefined)
            {
                switch (thermalMaterialType)
                {
                case ThermalMaterialType.Gas:
                    result = new GasMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, density, double.NaN, double.NaN);
                    break;

                case ThermalMaterialType.Liquid:
                    result = new LiquidMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, density, double.NaN, double.NaN);
                    break;

                case ThermalMaterialType.Solid:
                    if (transmitsLight)
                    {
                        result = new TransparentMaterial(material.Name, null, material.Name, description, thermalConductivity, double.NaN, density);
                    }
                    else
                    {
                        result = new OpaqueMaterial(material.Name, null, material.Name, description, thermalConductivity, double.NaN, density);
                    }
                    break;
                }
            }

            if (result == null)
            {
                string materialClass = material.MaterialClass?.Trim();
                if (string.IsNullOrWhiteSpace(materialClass))
                {
                    switch (materialClass.ToLower())
                    {
                    case "glass":
                        result = new TransparentMaterial(material.Name, materialClass, material.Name, description, thermalConductivity, double.NaN, density);
                        break;

                    case "gas":
                        result = new GasMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, density, double.NaN, double.NaN);
                        break;

                    case "ceramic":
                    case "earth":
                    case "brass":
                    case "metal":
                    case "wood":
                    case "concrete":
                    case "masonry":
                    case "paint":
                    case "paint/coating":
                    case "plastic":
                    case "stone":
                    case "textile":
                        result = new OpaqueMaterial(material.Name, materialClass, material.Name, description, thermalConductivity, double.NaN, density);
                        break;

                    case "liquid":
                        result = new LiquidMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, density, double.NaN, double.NaN);
                        break;
                    }
                }
            }

            if (result == null)
            {
                int transparency = material.Transparency;
                if (transparency < 10)
                {
                    result = new OpaqueMaterial(material.Name, null, material.Name, description, thermalConductivity, double.NaN, density);
                }
                else if (transparency < 100)
                {
                    result = new TransparentMaterial(material.Name, null, material.Name, description, thermalConductivity, double.NaN, density);
                }
                else
                {
                    result = new GasMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, double.NaN, density, double.NaN);
                }
            }

            if (result != null)
            {
                convertSettings?.Add(material.Id, result);
            }


            return(result);
        }
コード例 #10
0
        public static Autodesk.Revit.DB.Material ToRevit(this Material material, Document document, ConvertSettings convertSettings)
        {
            if (material == null || document == null)
            {
                return(null);
            }

            Autodesk.Revit.DB.Material result = convertSettings?.GetObject <Autodesk.Revit.DB.Material>(material.Guid);
            if (result != null)
            {
                return(result);
            }

            List <Autodesk.Revit.DB.Material> materials = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Material)).Cast <Autodesk.Revit.DB.Material>().ToList();

            if (materials != null)
            {
                result = materials.Find(x => x.Name == material.Name);
            }

            if (result == null)
            {
                ElementId elementId = Autodesk.Revit.DB.Material.Create(document, material.Name);
                if (elementId == null || elementId == ElementId.InvalidElementId)
                {
                    return(result);
                }

                result = document.GetElement(elementId) as Autodesk.Revit.DB.Material;
                if (result == null)
                {
                    return(result);
                }
            }

            if (material is GasMaterial)
            {
                result.MaterialClass = "Gas";
            }
            else if (material is SolidMaterial)
            {
            }
            else if (material is LiquidMaterial)
            {
                result.MaterialClass = "Liquid";
            }

            Parameter parameter = result.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION);

            parameter.Set(material.Description);

            ElementId elementId_ThermalAsset = result.ThermalAssetId;

            if (elementId_ThermalAsset != null && elementId_ThermalAsset != ElementId.InvalidElementId)
            {
                PropertySetElement propertySetElement = document.GetElement(elementId_ThermalAsset) as PropertySetElement;
                if (propertySetElement != null)
                {
                    ThermalAsset thermalAsset = propertySetElement.GetThermalAsset();
                    if (thermalAsset != null)
                    {
                        thermalAsset.Density             = material.Density;
                        thermalAsset.ThermalConductivity = material.ThermalConductivity;
                    }
                }
            }


            if (convertSettings.ConvertParameters)
            {
                Dictionary <string, object> parameters = convertSettings.GetParameters();

                Modify.SetValues(result, material);
                Modify.SetValues(result, material, ActiveSetting.Setting, parameters);
            }

            convertSettings?.Add(material.Guid, result);

            return(result);
        }
コード例 #11
0
        public static CarboElement getNewCarboElement(Document doc, Element el, ElementId materialIds, CarboRevitImportSettings settings)
        {
            CarboElement newCarboElement = new CarboElement();

            try
            {
                int    setId;
                string setName;
                string setImportedMaterialName;
                string setCategory;
                string setSubCategory;
                double setVolume;
                double setLevel;
                bool   setIsDemolished;
                bool   setIsSubstructure;
                bool   setIsExisting;
                //int layernr;

                // Material material = doc.GetElement(materialIds) as Material;
                //Id:
                setId = el.Id.IntegerValue;

                //Name (Type)
                ElementId   elId = el.GetTypeId();
                ElementType type = doc.GetElement(elId) as ElementType;
                setName = type.Name;

                //MaterialName
                setImportedMaterialName = doc.GetElement(materialIds).Name.ToString();

                //CarboMaterial carboMaterial = new CarboMaterial(setMaterialName);

                //GetDensity
                Parameter paramMaterial = el.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
                if (paramMaterial != null)
                {
                    Material material = doc.GetElement(paramMaterial.AsElementId()) as Material;
                    if (material != null)
                    {
                        PropertySetElement property = doc.GetElement(material.StructuralAssetId) as PropertySetElement;
                        if (property != null)
                        {
                            Parameter paramDensity = property.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_STRUCTURAL_DENSITY);
                            if (paramDensity != null)
                            {
                                double density = paramDensity.AsDouble();
                                newCarboElement.Density = density;
                            }
                        }
                    }
                }


                //Category
                setCategory = getValueFromList(el, type, settings.MainCategory, doc);

                //SubCategory
                setSubCategory = getValueFromList(el, type, settings.SubCategory, doc);

                //Volume

                double volumeCubicFt = el.GetMaterialVolume(materialIds);
                setVolume = Utils.convertToCubicMtrs(volumeCubicFt);

                newCarboElement.isDemolished = false;

                Level lvl = doc.GetElement(el.LevelId) as Level;
                if (lvl != null)
                {
                    setLevel = Convert.ToDouble((lvl.Elevation) * 304.8);
                }
                else
                {
                    setLevel = 0;
                }

                if (setLevel <= settings.CutoffLevelValue)
                {
                    setIsSubstructure = true;
                }
                else
                {
                    setIsSubstructure = false;
                }

                //Get Phasing;
                Phase elCreatedPhase = doc.GetElement(el.CreatedPhaseId) as Phase;
                Phase elDemoPhase    = doc.GetElement(el.DemolishedPhaseId) as Phase;


                if (elDemoPhase != null)
                {
                    setIsDemolished = true;
                }
                else
                {
                    setIsDemolished = false;
                }

                if (elCreatedPhase.Name == "Existing")
                {
                    setIsExisting = true;
                }
                else
                {
                    setIsExisting = false;
                }

                //Makepass;

                //Is existing and retained
                if (setIsExisting == true && setIsDemolished == false)
                {
                    if (settings.IncludeExisting == false)
                    {
                        return(null);
                    }
                }

                //Is demolished
                if (setIsDemolished == true)
                {
                    if (settings.IncludeDemo == false)
                    {
                        return(null);
                    }
                }

                //If it passed it is either proposed, or demolished and retained.

                newCarboElement.Id           = setId;
                newCarboElement.Name         = setName;
                newCarboElement.MaterialName = setImportedMaterialName;
                newCarboElement.Category     = setCategory;
                newCarboElement.SubCategory  = setSubCategory;
                newCarboElement.Volume       = Math.Round(setVolume, 4);
                //newCarboElement.Material = carboMaterial; //Material removed
                newCarboElement.Level          = Math.Round(setLevel, 3);
                newCarboElement.isDemolished   = setIsDemolished;
                newCarboElement.isExisting     = setIsExisting;
                newCarboElement.isSubstructure = setIsSubstructure;

                if (newCarboElement.Volume != 0)
                {
                    return(newCarboElement);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                //TaskDialog.Show("Error", ex.Message);
                return(null);
            }
        }