参数的值可能是一个整数,一个字符串,也可能是一个元素对象。比如是一种材质。
材质也分多种,管道有管道对齐的材质。
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Architecture;
using System.Xml;
namespace RevitCodes
{
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdParameter : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
Selection sel = uiApp.ActiveUIDocument.Selection;
Transaction ts = new Transaction(doc, " http://revit.5d6d.com " );
ts.Start();
// 选中的元素,这里选中一个管道Pipe
Element elemPick = null ;
foreach (Element elem in sel.Elements)
{
elemPick = elem;
break ;
}
// 遍历元素的普通参数
string strParameter = "" ;
foreach (Parameter p in elemPick.Parameters)
{
strParameter += p.Definition.ParameterGroup + " , " + p.Definition.Name + " , " + p.AsValueString() + " \n " ;
}
TaskDialog.Show( " parameter " , strParameter);
// 遍历元素的类型属性
Pipe pipe = elemPick as Pipe;
foreach (Parameter p in pipe.PipeType.Parameters)
{
if (p.Definition.Name == " 材质 " )
{
// 元素的参数值可能是一个元素,比如材质的参数值是一个Material元素
PipeMaterialType pipeMater = doc.get_Element(p.AsElementId()) as PipeMaterialType;
// 材质还分管道材质这里不能转化为Material
TaskDialog.Show( " 类型属性 " , pipeMater.Category.Name + " , " + pipeMater.Name);
}
}
// 系统包含的材质元素
string strMaterial = "" ;
Materials materials = doc.Settings.Materials;
foreach (Material ma in materials)
{
strMaterial += ma.Name + " \n " ;
}
TaskDialog.Show( " Material " , strMaterial);
ts.Commit();
return Result.Succeeded;
}
// 元素的参数,参数组,即属性面版中可以折叠的部分,这里读Pipe
public Parameter FindParameter(Element element)
{
Parameter foundParameter = null ;
int i = 0 ;
foreach (Parameter parameter in element.Parameters)
{
// BuiltInParameterGroup.PG_MECHANICAL // 机械
// BuiltInParameterGroup.PG_CONSTRAINTS // 限制条件
// BuiltInParameterGroup.PG_GEOMETRY // 尺寸标注
// BuiltInParameterGroup.PG_PHASING // 阶段化
// BuiltInParameterGroup.PG_IDENTITY_DATA // 标识数据
// BuiltInParameterGroup.PG_INSULATION // 绝缘层
if (BuiltInParameterGroup.PG_GEOMETRY == parameter.Definition.ParameterGroup)
{
TaskDialog.Show( " g " , parameter.Definition.Name);
i += 1 ;
}
Definition definition = parameter.Definition; // 参数的基类
// 过滤参数
if (definition.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS &&
definition.ParameterType == ParameterType.Material)
{
foundParameter = parameter;
break ;
}
}
TaskDialog.Show( " i " , i + " 个 " );
return foundParameter;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Architecture;
using System.Xml;
namespace RevitCodes
{
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdParameter : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
Selection sel = uiApp.ActiveUIDocument.Selection;
Transaction ts = new Transaction(doc, " http://revit.5d6d.com " );
ts.Start();
// 选中的元素,这里选中一个管道Pipe
Element elemPick = null ;
foreach (Element elem in sel.Elements)
{
elemPick = elem;
break ;
}
// 遍历元素的普通参数
string strParameter = "" ;
foreach (Parameter p in elemPick.Parameters)
{
strParameter += p.Definition.ParameterGroup + " , " + p.Definition.Name + " , " + p.AsValueString() + " \n " ;
}
TaskDialog.Show( " parameter " , strParameter);
// 遍历元素的类型属性
Pipe pipe = elemPick as Pipe;
foreach (Parameter p in pipe.PipeType.Parameters)
{
if (p.Definition.Name == " 材质 " )
{
// 元素的参数值可能是一个元素,比如材质的参数值是一个Material元素
PipeMaterialType pipeMater = doc.get_Element(p.AsElementId()) as PipeMaterialType;
// 材质还分管道材质这里不能转化为Material
TaskDialog.Show( " 类型属性 " , pipeMater.Category.Name + " , " + pipeMater.Name);
}
}
// 系统包含的材质元素
string strMaterial = "" ;
Materials materials = doc.Settings.Materials;
foreach (Material ma in materials)
{
strMaterial += ma.Name + " \n " ;
}
TaskDialog.Show( " Material " , strMaterial);
ts.Commit();
return Result.Succeeded;
}
// 元素的参数,参数组,即属性面版中可以折叠的部分,这里读Pipe
public Parameter FindParameter(Element element)
{
Parameter foundParameter = null ;
int i = 0 ;
foreach (Parameter parameter in element.Parameters)
{
// BuiltInParameterGroup.PG_MECHANICAL // 机械
// BuiltInParameterGroup.PG_CONSTRAINTS // 限制条件
// BuiltInParameterGroup.PG_GEOMETRY // 尺寸标注
// BuiltInParameterGroup.PG_PHASING // 阶段化
// BuiltInParameterGroup.PG_IDENTITY_DATA // 标识数据
// BuiltInParameterGroup.PG_INSULATION // 绝缘层
if (BuiltInParameterGroup.PG_GEOMETRY == parameter.Definition.ParameterGroup)
{
TaskDialog.Show( " g " , parameter.Definition.Name);
i += 1 ;
}
Definition definition = parameter.Definition; // 参数的基类
// 过滤参数
if (definition.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS &&
definition.ParameterType == ParameterType.Material)
{
foundParameter = parameter;
break ;
}
}
TaskDialog.Show( " i " , i + " 个 " );
return foundParameter;
}
}
}