Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit API: how to put revit links to Combobox

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
KStaseva
403 Views, 5 Replies

Revit API: how to put revit links to Combobox

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?

5 REPLIES 5
Message 2 of 6
jeremy_tammik
in reply to: KStaseva

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.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 6
ricaun
in reply to: KStaseva

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}" />

...

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 4 of 6
KStaseva
in reply to: ricaun

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!

Message 5 of 6
ricaun
in reply to: KStaseva

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!

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 6 of 6
KStaseva
in reply to: ricaun

Yes, that worked !!! Thank you much!!!😀

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community