【发布时间】:2021-07-20 19:25:21
【问题描述】:
我需要为 Revit 中的模型获取和设置一组参数的新值,因此我尝试为其创建一个插件,以便获取 JSON 文件并在模型中实现。我尝试使用此代码获取测试参数,但它一直返回 null。我在 revit 上将参数创建到家庭中以尝试此操作。不知道是不是这个问题。
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
Element e = SelectElement(uidoc, doc);
Parameter parameter = e.LookupParameter("comment_test");
using(Transaction t = new Transaction(doc, "parameter"))
{
t.Start("param");
try
{
parameter.Set("Test Comment");
}
catch { }
t.Commit();
}
return Result.Succeeded;
}
//Select the element
public Element SelectElement(UIDocument uidoc, Document doc)
{
Reference r = uidoc.Selection.PickObject(ObjectType.Element);
Element el= uidoc.Document.GetElement(r);
return el;
}
// Get the param value and return as string
public string GetParameterValue(Parameter parameter)
{
switch (parameter.StorageType)
{
case StorageType.ElementId:
return parameter.AsElementId().IntegerValue.ToString();
case StorageType.Integer:
case StorageType.None:
case StorageType.Double:
return parameter.AsValueString();
case StorageType.String:
return parameter.AsString();
default:
return "";
}
}
在我得到这段代码的同一个地方,我得到另一个返回内置参数的地方,所以我尝试了我在视频中看到的,但它在调试时也返回 null。
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
Element e = SelectElement(uidoc, doc);
Parameter parametro = e.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION);
using(Transaction t = new Transaction(doc, "parametro"))
{
t.Start("param");
try
{
parametro.Set("Teste de Inserção de Comentário");
}
catch { }
t.Commit();
}
return Result.Succeeded;
}
【问题讨论】: