コード例 #1
0
        static Material GetMaterial(Document doc, Floor floor)
        {
            FloorType aFloorType = floor.FloorType;

            if (!aFloorType.IsFoundationSlab)
            {
                CompoundStructure comStruct     = aFloorType.GetCompoundStructure();
                Categories        allCategories = doc.Settings.Categories;

                Category floorCategory = allCategories.get_Item(BuiltInCategory.OST_Floors);
                Material floorMat      = floorCategory.Material;

                foreach (var structLayer in comStruct.GetLayers())
                {
                    var layerMat = ElementFilterUtils.GetElement(doc, structLayer.MaterialId) as Material;
                    if (layerMat == null)
                    {
                        switch (structLayer.Function)
                        {
                        case MaterialFunctionAssignment.Structure:
                            layerMat = allCategories.get_Item(BuiltInCategory.OST_FloorsStructure).Material;
                            break;
                        }
                    }
                    if (layerMat != null)
                    {
                        floorMat = layerMat;
                        break;
                    }
                }
                return(floorMat);
            }
            return(null);
        }
コード例 #2
0
 static Material GetParamMaterial(Document doc, Element inst)
 {
     foreach (Parameter p in inst.Parameters)
     {
         var def = p.Definition;
         if (p.StorageType == StorageType.ElementId)
         {
             if (def.ParameterType == ParameterType.Material) //||def.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS
             {
                 var matId = p.AsElementId();
                 if (matId.Compare(ElementId.InvalidElementId) == 0)
                 {
                     if (inst.Category != null)
                     {
                         return(inst.Category.Material);
                     }
                 }
                 else
                 {
                     return(ElementFilterUtils.GetElement(doc, matId) as Material);
                 }
             }
         }
     }
     return(null);
 }
コード例 #3
0
        internal static Material GetMaterial(Document doc, Wall wall)
        {
            WallType aWallType = wall.WallType;

            if (WallKind.Basic == aWallType.Kind)
            {
                CompoundStructure comStruct     = aWallType.GetCompoundStructure();
                Categories        allCategories = doc.Settings.Categories;
                // Get the category OST_Walls default Material;
                // use if that layer's default Material is <By Category>
                Category wallCategory = allCategories.get_Item(BuiltInCategory.OST_Walls);
                Material wallMaterial = wallCategory.Material;
                foreach (CompoundStructureLayer structLayer in comStruct.GetLayers())
                {
                    var layerMaterial = ElementFilterUtils.GetElement(doc, structLayer.MaterialId) as Material;
                    if (layerMaterial == null)
                    {
                        switch (structLayer.Function)
                        {
                        case MaterialFunctionAssignment.Structure:
                            layerMaterial = allCategories.get_Item(BuiltInCategory.OST_WallsStructure).Material;
                            break;
                        }
                    }
                    if (layerMaterial != null)
                    {
                        wallMaterial = layerMaterial;
                        break;
                    }
                }
                return(wallMaterial);
            }

            return(null);
        }
コード例 #4
0
        public static Material GetMaterial(Element elem, Document doc)
        {
            if (doc == null)
            {
                doc = elem.Document;
            }
            if (elem is Wall)
            {
                var mat0 = GetMaterial(doc, (Wall)elem);
                if (mat0 != null)
                {
                    return(mat0);
                }
            }
            else if (elem is Floor)
            {
                var mat0 = GetMaterial(doc, (Floor)elem);
                if (mat0 != null)
                {
                    return(mat0);
                }
            }
            else
            {
                var mat0 = GetParamMaterial(doc, elem);
                if (mat0 != null)
                {
                    return(mat0);
                }
            }
            var ids = elem.GetMaterialIds(false);

            if (ids.Count > 0)
            {
                foreach (var mzId in ids)
                {
                    var      mz   = ElementFilterUtils.GetElement(doc, mzId) as Material;
                    Material mat0 = mz;
                    if (mat0 != null)
                    {
                        return(mat0);
                    }
                }
            }
            //附加材质
            if (elem.Category != null)
            {
                Material mat = elem.Category.Material;
                if (mat != null)
                {
                    return(mat);
                }
                return(mat);
            }
            return(null);
        }
コード例 #5
0
ファイル: ParameterUtils.cs プロジェクト: weijx-xa/test
        private static string AsElementName(Document doc, ElementId idVal)
        {
            if (idVal.Compare(ElementId.InvalidElementId) == 0)
            {
                return(Convert.ToString(idVal.IntegerValue));
            }
            var ele = ElementFilterUtils.GetElement(doc, idVal);

            if (ele == null)
            {
                return(null);
            }
            return(ele.Name);
        }
コード例 #6
0
        /// <summary>
        /// 从构件上获取楼层信息
        /// </summary>
        /// <param name="e"></param>
        /// <param name="doc"></param>
        /// <param name="units"></param>
        /// <returns></returns>
        public static LevelElement GetLevel(this Autodesk.Revit.DB.Element e, Document doc, UnitConversionFactors units)
        {
            if (!e.LevelId.Equals(ElementId.InvalidElementId))
            {
                var level = (Level)ElementFilterUtils.GetElement(doc, e.LevelId);
                return(level.GetLevel(units));
            }
            var l = GetLevelFromParam(doc, e);

            if (l != null)
            {
                return(l.GetLevel(units));
            }
            return(null);
        }
コード例 #7
0
        private static Level GetLevelFromParam(Document doc, Autodesk.Revit.DB.Element e)
        {
            //var name = "参照标高";
            //string value = string.Empty;
            var ps     = e.Parameters;
            var psIter = ps.ForwardIterator();

            while (psIter.MoveNext())
            {
                var p = (Parameter)psIter.Current;
                if (p.StorageType == StorageType.ElementId)
                {
                    var element = ElementFilterUtils.GetElement(doc, p.AsElementId()) as Level;
                    if (element != null)
                    {
                        return(element);
                    }
                }
            }
            return(null);
        }