Revit API判断参数的类型
参数的值可能是数值也可以是字符串,或者是另外一个元素。
通过StorageType可以判断参数是什么类型,再根据参数类型找到参数的值。
from:http://revit.5d6d.com/thread-1344-1-1.html
通过StorageType可以判断参数是什么类型,再根据参数类型找到参数的值。
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdCheckParam : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string messages, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Selection sel = uiDoc.Selection;
Transaction ts = new Transaction(uiDoc.Document, "参数类型");
ts.Start();
Reference refDuct = sel.PickObject(ObjectType.Element, "选择风管");
Element el = doc.GetElement(refDuct);
foreach (Parameter p in el.Parameters)
{
if (p.Definition.Name == "高度")
{
TaskDialog.Show("height", GetParamVal(doc, p));
}
if (p.Definition.Name == "系统类型")
{
TaskDialog.Show("cate", GetParamVal(doc, p));
}
}
ts.Commit();
return Result.Succeeded;
}
public string GetParamVal(Document doc, Parameter p)
{
string strResult = "";
switch (p.StorageType)
{
case StorageType.Double:
strResult = p.AsValueString();
break;
case StorageType.ElementId:
strResult = doc.get_Element(p.AsElementId()).Name;
break;
}
return strResult;
}
}
[Regeneration(RegenerationOption.Manual)]
public class cmdCheckParam : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string messages, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Selection sel = uiDoc.Selection;
Transaction ts = new Transaction(uiDoc.Document, "参数类型");
ts.Start();
Reference refDuct = sel.PickObject(ObjectType.Element, "选择风管");
Element el = doc.GetElement(refDuct);
foreach (Parameter p in el.Parameters)
{
if (p.Definition.Name == "高度")
{
TaskDialog.Show("height", GetParamVal(doc, p));
}
if (p.Definition.Name == "系统类型")
{
TaskDialog.Show("cate", GetParamVal(doc, p));
}
}
ts.Commit();
return Result.Succeeded;
}
public string GetParamVal(Document doc, Parameter p)
{
string strResult = "";
switch (p.StorageType)
{
case StorageType.Double:
strResult = p.AsValueString();
break;
case StorageType.ElementId:
strResult = doc.get_Element(p.AsElementId()).Name;
break;
}
return strResult;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。