Revit二次开发之“遍历材质判断材质类别的新方法”BuiltInParameter.PHY_MATERIAL_PARAM_CLASS
2011-09-19 08:11
411 查看
老版本API的方法:
if (material is MaterialSteel)
新版本API的方法:
Parameter curPara = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS);
if (curPara.AsInteger()==(int)StructuralMaterialType.Steel)
全部代码如下:[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdMaterial : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
collector.OfClass(typeof(Material));
FilteredElementIterator materialItr = collector.GetElementIterator();
materialItr.Reset();
int i = 0;
#region 新方法
while (materialItr.MoveNext())
{
Material material = materialItr.Current as Material;
Parameter curPara = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS);
switch (curPara.AsInteger())
{
case (int)StructuralMaterialType.Steel:
TaskDialog.Show("新方法", material.Name);
break;
}
}
#endregion
#region 过时的方法
materialItr.Reset();
while (materialItr.MoveNext())
{
i = i + 1;
Material material = materialItr.Current as Material;
if (material is MaterialSteel)//steel金属
{
MaterialSteel steelMa = material as MaterialSteel;
TaskDialog.Show("steel", steelMa.Name);
}
}
#endregion
TaskDialog.Show("count", i + "");
return Result.Succeeded;
}
}from:http://revit.5d6d.com/thread-1253-1-1.html
if (material is MaterialSteel)
新版本API的方法:
Parameter curPara = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS);
if (curPara.AsInteger()==(int)StructuralMaterialType.Steel)
全部代码如下:[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdMaterial : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
collector.OfClass(typeof(Material));
FilteredElementIterator materialItr = collector.GetElementIterator();
materialItr.Reset();
int i = 0;
#region 新方法
while (materialItr.MoveNext())
{
Material material = materialItr.Current as Material;
Parameter curPara = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS);
switch (curPara.AsInteger())
{
case (int)StructuralMaterialType.Steel:
TaskDialog.Show("新方法", material.Name);
break;
}
}
#endregion
#region 过时的方法
materialItr.Reset();
while (materialItr.MoveNext())
{
i = i + 1;
Material material = materialItr.Current as Material;
if (material is MaterialSteel)//steel金属
{
MaterialSteel steelMa = material as MaterialSteel;
TaskDialog.Show("steel", steelMa.Name);
}
}
#endregion
TaskDialog.Show("count", i + "");
return Result.Succeeded;
}
}from:http://revit.5d6d.com/thread-1253-1-1.html
相关文章推荐
- Revit二次开发高级专题讲座:访问Revit模型中的几何数据以及对象间关系判断方法(点击下载)
- maven/plugin开发:插件版本不匹配导致的报错:Method: ‘name’ not found in class in ParameterAnnotationContent
- @RequestParam注解使用:Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.
- ios开发之小总结「类与对象的判断方法和遍历字典的方法」
- ios开发之小总结「类与对象的判断方法和遍历字典的方法」
- React.createElement: type is invalid -- expected a string (for built-in components) or a class/funct
- iOS开发之 -- 判断tableview/scrollview的滑动方法
- java JNI调用C语言动态链接库(java.lang.UnsatisfiedLinkError: no yourClassName in java.library.path 异常的解决方法)
- Revit二次开发入门——重要的属性和方法
- iOS开发 判断代理以及代理方法是否有人遵循
- 百度地图开发中的java.lang.ClassCastException解决方法及定位源码
- 遍历集合,判断并添加元素的集中方法
- iOS开发中判断字符串为空的方法
- 缺少 mysqli 扩展和Fatal Error: Class 'mysqli' not found in... 解决方法
- 判断整数序列是否为二元查找树的后序遍历结果的解决方法
- [置顶] JAVA中 错误代码是 the public type must be defined in its own file 解决方法 android开发 java编程
- iOS开发之使用block块进行数据遍历的方法
- Error creating bean with name ‘…’defined in class path resource[applicationContext2.xml]:问题及其解决方法
- Android 开发问题解决方法记录:Dx unsupported class file version 52.0
- MyBatis错误:There is no getter for property named 'paramSql' in 'class java.lang.String'