简体   繁体   English

Revit API:如何将 Revit 链接放入 Combobox

[英]Revit API: how to put revit links to Combobox

I'm new to Revit API.我是 Revit API 的新手。 And I can't see the Revit links from the Method in the 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;
}

In MVVM I use:在 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);
}

But in the ComboBox finally I see only empty lines.但在 ComboBox 最后我只看到空行。 So, the docs are not seen in the ComboBox.因此,在 ComboBox 中看不到文档。 May be someone faced the same problem?可能有人面临同样的问题? enter image description here在此处输入图像描述

I think you may have two main issues.我认为您可能有两个主要问题。 I've not seen .ToList() for the FilteredElementCollector class before, you probably want .ToElements() - that gives you an IList<Element> ToElements RevitAPIDocs我以前没有见过FilteredElementCollector类的.ToList() ,你可能想要.ToElements() - 它给你一个IList<Element> ToElements RevitAPIDocs

You also don't have the XAML (Assuming some things here) shown.您也没有显示 XAML(假设这里有一些东西)。 Check to see that you're binding that list into the window correctly.检查您是否将该列表正确绑定到窗口中。 I typically set the item source in the code so something simple like:我通常在代码中设置项目源,所以很简单,例如:

LinkedInstances = LinkUtils.GetAllRevitLinkInstances(commandData);    
LinkedDocsComboBox.Items = LinkedInstances;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM