public MaterialInfo(ElementId baseMatId, string layerName, double matWidth, MaterialFunctionAssignment function)
 {
     m_baseMatId = baseMatId;
     m_layerName = layerName;
     m_matWidth  = matWidth;
     m_function  = function;
 }
Esempio n. 2
0
        /// <summary>
        /// Gets the material ids of finish function of the host object.
        /// </summary>
        /// <param name="hostObject">The host object.</param>
        /// <returns>The material ids.</returns>
        public static ISet <ElementId> GetFinishMaterialIds(HostObject hostObject)
        {
            HashSet <ElementId> matIds = new HashSet <ElementId>();

            ElementId         typeElemId  = hostObject.GetTypeId();
            HostObjAttributes hostObjAttr = hostObject.Document.GetElement(typeElemId) as HostObjAttributes;

            if (hostObjAttr == null)
            {
                return(matIds);
            }

            ElementId         baseMatId = CategoryUtil.GetBaseMaterialIdForElement(hostObject);
            CompoundStructure cs        = hostObjAttr.GetCompoundStructure();

            if (cs != null)
            {
                for (int i = 0; i < cs.LayerCount; ++i)
                {
                    MaterialFunctionAssignment function = cs.GetLayerFunction(i);
                    if (function == MaterialFunctionAssignment.Finish1 || function == MaterialFunctionAssignment.Finish2)
                    {
                        ElementId matId = cs.GetMaterialId(i);
                        if (matId != ElementId.InvalidElementId)
                        {
                            matIds.Add(matId);
                        }
                        else if (baseMatId != ElementId.InvalidElementId)
                        {
                            matIds.Add(baseMatId);
                        }
                    }
                }
            }

            return(matIds);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

#if _2011
            //
            // code for the Revit 2011 API:
            //
            Debug.Assert(false,
                         "Currently, no new wall layer can be created, because"
                         + "there is no creation method available for it.");

            foreach (WallType wallType in doc.WallTypes)
            {
                if (0 < wallType.CompoundStructure.Layers.Size)
                {
                    CompoundStructureLayer oldLayer
                        = wallType.CompoundStructure.Layers.get_Item(0);

                    WallType newWallType
                        = wallType.Duplicate("NewWallType") as WallType;

                    CompoundStructure structure
                        = newWallType.CompoundStructure;

                    CompoundStructureLayerArray layers
                        = structure.Layers;


                    // from here on, nothing works, as expected:
                    // in the Revir 2010 API, we could call the constructor
                    // even though it is for internal use only.
                    // in 2011, it is not possible to call it either.

                    CompoundStructureLayer newLayer = null;
                    //  = new CompoundStructureLayer(); // for internal use only

                    newLayer.DeckProfile = oldLayer.DeckProfile;
                    //newLayer.DeckUsage = oldLayer.DeckUsage; // read-only
                    //newLayer.Function = oldLayer.Function; // read-only
                    newLayer.Material  = oldLayer.Material;
                    newLayer.Thickness = oldLayer.Thickness;
                    newLayer.Variable  = oldLayer.Variable;
                    layers.Append(newLayer);
                }
            }
#endif // _2011

            //WallTypeSet wallTypes = doc.WallTypes; // 2013

            FilteredElementCollector wallTypes
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(WallType)); // 2014

            foreach (WallType wallType in wallTypes)
            {
                if (0 < wallType.GetCompoundStructure().GetLayers().Count)
                {
                    CompoundStructureLayer oldLayer
                        = wallType.GetCompoundStructure().GetLayers()[0];

                    WallType newWallType
                        = wallType.Duplicate("NewWallType") as WallType;

                    CompoundStructure structure
                        = newWallType.GetCompoundStructure();

                    IList <CompoundStructureLayer> layers
                        = structure.GetLayers();

                    // in Revit 2012, we can create a new layer:

                    double width = 0.1;
                    MaterialFunctionAssignment function = oldLayer.Function;
                    ElementId materialId = oldLayer.MaterialId;

                    CompoundStructureLayer newLayer
                        = new CompoundStructureLayer(width, function, materialId);

                    layers.Add(newLayer);
                    structure.SetLayers(layers);
                    newWallType.SetCompoundStructure(structure);
                }
            }
            return(Result.Succeeded);
        }