Reputation: 1
I'm new to Revit API. And I can't see the Revit links from the Method in the ComboBox.
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:
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. So, the docs are not seen in the ComboBox. May be someone faced the same problem?enter image description here
Upvotes: 0
Views: 243
Reputation: 1
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
You also don't have the XAML (Assuming some things here) shown. 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;
Upvotes: 0