我使用了 if 语句来检查检索模式的方法是否为 null,这是一个单独的表单,其中包含要填充的 checkedListBox。代码在下面,我已经标记了检查这个的条件。我的问题是;确保每次在新的 .rvt 文件中运行 revit 加载项时,在尝试检索架构之前架构记录已经存在的最有效方法是什么?当事情出错时,在尝试访问空模式时会发生空引用错误。
//CheckedListBox for filter01 this exists in the form and calls the main
class function to retrieve the record.
checkedListBox1.DataSource = WS.categoryList(rvtDoc, intSwitch = 1);
Filter01_CategoryList = new List<BuiltInCategory>();
**if (WS.retSchemaBICMethod(rvtDoc) != null)**
{
TaskDialog.Show("Schema 1 ", " exists");
Filter01_CategoryList = WS.retSchemaBICMethod(rvtDoc);
}
else
{
TaskDialog.Show("Schema 1 "," has not been created");
//Update stored schema field values
inputBIC = checkedListBox1.CheckedItems.Cast<BuiltInCategory>
().ToList<BuiltInCategory>();
WS.getSetBIC(rvtDoc, inputBIC);
WS.storeSchema(rvtDoc, WS.projectInfoElement, inputBIC,
out WS.retrieveBIC);
//set checkedlistbox 1
Filter01_CategoryList = WS.retSchemaBICMethod(rvtDoc);
}
//this code returns the retrieved schema from the main class
public List<BuiltInCategory>retSchemaBICMethod(Document doc)
{
Element piElement = projectInfoFilter(doc);
// Read back the data from ProjInfo
Entity retrievedEntity = piElement.GetEntity(Schema.Lookup(schemaGuid));
IList<int> retrievedData = retrievedEntity.Get<IList<int>>
(Schema.Lookup(schemaGuid).GetField("BuiltInCatIds"));
//cast int list back to built-in category list
retSchemaBIC = retrievedData.Cast<BuiltInCategory>
().ToList<BuiltInCategory>();
return retSchemaBIC;
}