参数的值可能是数值也可以是字符串,或者是另外一个元素。
通过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;
    }
}
from:http://revit.5d6d.com/thread-1344-1-1.html

相关文章:

  • 2021-04-10
  • 2021-08-15
  • 2022-12-23
  • 2021-05-03
  • 2021-10-03
  • 2021-09-12
猜你喜欢
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2021-05-30
  • 2022-12-23
相关资源
相似解决方案