Revit的参数类型包含很多,比如下面列表所示。
Text The parameter data should be interpreted as a string of text. Integer The parameter data should be interpreted as a whole number, positive or negative. Number The parameter data should be interpreted as a real number, possibly including decimal points. Length The parameter data represents a length. Area The parameter data represents an area. Volume The parameter data represents a volume. Angle The parameter data represents an angle. URL A text string that represents a web address. Material The value of this property is considered to be a material. YesNo A boolean value that will be represented as Yes or No. Force The data value will be represented as a force. LinearForce The data value will be represented as a linear force. AreaForce The data value will be represented as an area force. Moment The data value will be represented as a moment. NumberOfPoles A parameter value that represents the number of poles, as used in electrical disciplines. FixtureUnit A parameter value that represents the fixture units, as used in piping disciplines. FamilyType A parameter used to control the type of a family nested within another family.
其中我们看到有的是Material型,或FamilyType型。
对于字符串,整形,长度(double)型,我们可以分别通过Parameter.AsString(), Parameter.AsInteger(), AsDouble()等来访问。
那么如果是Material类型的,怎么获取具体这个材料是什么呢? 此时存在在参数中的实际上是一个元素id即ElementId。
可以用Parameter.AsElementId()方法获得元素Id,然后用Document.get_Element(ElementId id) 方法获取这个材料对象。
请看下面的代码获取柱子的材料,并在任务框上显示材料名称。
public class RevitCommand : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; //pick the column, Selection sel = app.ActiveUIDocument.Selection; Reference ref1 = sel.PickObject(ObjectType.Element, "Please pick a column to get its Materai parameter value"); Element elem = ref1.Element; // the material parameter name for column is "Column Material" Parameter param = room.get_Parameter("Column Material"); ElementId idMaterial = param.AsElementId(); Material mat = doc.get_Element(idMaterial) as Material; MessageBox.Show("The material name is" + mat.Name); return Result.Succeeded ; } }
这个方法可以获取任何参数值是其它Revit对象的参数值。