Hello, Colleagues,
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); } 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?
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?
Solved! Go to Solution.
Solved by ricaun. Go to Solution.
Solved by ricaun. Go to Solution.
I do not see the code where you populate the combo box, so I cannot tell what might be going wrong.
Have you examined the list of linked documents linkedDocs in the debugger to ensure that you have successfully collected the expected data? Have you successfully debugged the rest of the steps populating the combo box? In the debugger, you should be able to see immediately where things are going wrong.
How your ComboBox XAML looks like? I supposed the problem was in the Binding or the DisplayMemberPath.
Some like this maybe work
<ComboBox ItemsSource="{Binding LinkedInstances}"
DisplayMemberPath="Title"
SelectedValue="{Binding SelectedLinkedInstances}" />
...
Yes, thank you so much!!!!
my xaml was :
<ComboBox ItemsSource="{Binding LinkedInstances}"
SelectedValue="{Binding SelectedLinkedInstances}"
DisplayMemberPath="Name"
Margin="5" Grid.Row="1" Grid.Column="1"/>
My stupid misteake!
I believe Name does not exist on the Document Properties. That's the reason is showing empty. You could use Title instead.
Or is it a better approach to create your own model based on the Document.
Something like...
public class DocumentModel
{
private Document document;
public DocumentModel(Document document)
{
this.document = document;
}
public Document Document => document;
public string Name => document.Title;
}
With my own Name propriety.
I hope this helps...
See yaa!
Can't find what you're looking for? Ask the community or share your knowledge.