示例#1
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);
        }
示例#2
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();
     }
 }
示例#3
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);
        }