我刚开始使用Revit。在ComboBox中,我看不到方法中的Revit链接。
public static IList<Document> GetAllRevitLinkInstances(ExternalCommandData commandData)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document arDoc = uidoc.Document;
FilteredElementCollector collector = new
FilteredElementCollector(arDoc);
collector.OfClass(typeof(RevitLinkInstance)).ToList();
IList<Document> linkedDocs = new List<Document>();
foreach (Element elem in collector)
{
RevitLinkInstance instance = elem as RevitLinkInstance;
Document linkDoc = instance.GetLinkDocument();
linkedDocs.Add(linkDoc);
// linkedDocs.Add(string.Format("{0}.rvt",
linkDoc.Title.ToString()));
//linkedDocs.AppendLine("FileName: " + Path.GetFileName(linkDoc.PathName));
//RevitLinkType type = arDoc.GetElement(instance.GetTypeId()) as RevitLinkType;
//linkedDocs.AppendLine("Is Nested: " + type.IsNestedLink.ToString());
}
return linkedDocs;
}在MVVM中,我使用:
public Document SelectedLinkedInstances { get; set; }
public IList<Document> LinkedInstances { get; } = new List<Document>();
public MainViewViewModel(ExternalCommandData commandData)
{
_commandData = commandData;
SaveCommand = new DelegateCommand(OnSaveCommand);
LinkedInstances = LinkUtils.GetAllRevitLinkInstances(commandData);
}但在ComboBox中,我只看到空行。因此,在ComboBox中看不到这些文档。可能是有人面临同样的问题吗?在这里输入图像描述
发布于 2022-06-27 17:41:23
我想你可能有两个主要问题。我以前没有见过.ToList()用于FilteredElementCollector类,您可能需要.ToElements() --这给了您一个IList<Element> ToElements RevitAPIDocs
您也没有显示XAML (假设这里有一些东西)。检查是否正确地将该列表绑定到窗口。我通常在代码中设置项目源代码,这样做很简单,比如:
LinkedInstances = LinkUtils.GetAllRevitLinkInstances(commandData);
LinkedDocsComboBox.Items = LinkedInstances;https://stackoverflow.com/questions/72683281
复制相似问题