通过收集将使用过的制造服务列表添加到组合框中



我有一些问题得到这个工作。我试图得到一个列表的使用制造服务出现在一个组合框中,以便可以选择和隔离该服务,以重新编号与该服务相关的任何东西。我不确定我是否走对了方向。仍然是新的revit api。catch

出错Dubug错误

System.Windows。数据错误:40:BindingExpression路径错误:'IsCheckboxEnabled'属性未在'对象''ServiceGroup' (HashCode=30800802)'上找到。BindingExpression:路径= IsCheckboxEnabled;DataItem = ' ServiceGroup ' (HashCode = 30800802);目标元素是'ServiceGroupCheckBox' (Name= ");目标属性为"IsEnabled"(类型为"Boolean")

try
{
ICollection<FabricationService> fabricationService =
(ICollection<FabricationService>)new FilteredElementCollector(Doc, Doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_FabricationPipework)
.ToElements();
{
foreach (FabricationService service in fabricationService)
comboBox2.Items.Add(service);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

您链接的图像显示错误:

无法强制转换类型的对象1 (Autodesk.Revit.DB System.Collections.Generic.List。元素]'到类型System.Collections.Generic.ICollection 1 [Autodesk.Revit.DB.FabricationService] '。

你有一个转换错误,试着像这样转换:

using System.Linq;
IEnumerable<FabricationService> fabricationServices =
new FilteredElementCollector(doc, doc.ActiveView.Id)
.OfCategory(BuiltInCategory.OST_FabricationPipework)
.Cast<FabricationService>();
foreach (FabricationService fabricationService in fabricationServices)
{
comboBox2.Items.Add(fabricationService);
}

我猜FabricationService对象返回与您上面指定的内置类别,我不使用这些在我的工作。您也可以使用类过滤器:

IEnumerable<FabricationService> fabricationServices =
new FilteredElementCollector(doc, doc.ActiveView.Id)
.OfClass(typeof(FabricationService))
.Cast<FabricationService>();

最新更新