首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Revit :如何放置到Combobox的revit链接

Revit :如何放置到Combobox的revit链接
EN

Stack Overflow用户
提问于 2022-06-20 06:57:41
回答 1查看 97关注 0票数 0

我刚开始使用Revit。在ComboBox中,我看不到方法中的Revit链接。

代码语言:javascript
复制
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中,我使用:

代码语言:javascript
复制
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中看不到这些文档。可能是有人面临同样的问题吗?在这里输入图像描述

EN

回答 1

Stack Overflow用户

发布于 2022-06-27 17:41:23

我想你可能有两个主要问题。我以前没有见过.ToList()用于FilteredElementCollector类,您可能需要.ToElements() --这给了您一个IList<Element> ToElements RevitAPIDocs

您也没有显示XAML (假设这里有一些东西)。检查是否正确地将该列表绑定到窗口。我通常在代码中设置项目源代码,这样做很简单,比如:

代码语言:javascript
复制
LinkedInstances = LinkUtils.GetAllRevitLinkInstances(commandData);    
LinkedDocsComboBox.Items = LinkedInstances;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72683281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档