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

Pick FamilySymbol from Project Browser?

Message 1 of 7
434 Views, 6 Replies

Pick FamilySymbol from Project Browser?


I want my user to select a FamilySymbol that's already loaded from the UI (more specifically, the Project Browser) that I then further process in my own code. I'm aware that there are different methods for filtering the already existing custom families/loading families from file and so on, but is there a way to prompt the user to pick one from the project browser? Ideally, it would NOT require the user to make conscious decisions on where to click before starting the add-in.




Labels (2)
Message 2 of 7
in reply to: grubdex



you can ask users to select element(s) instance from their view then manage to get the FamilySymbol, but i don't think it's possible from the browser.


Message 3 of 7
in reply to: grubdex

It's not the usual workflow but now in 2023 you have the selection changed event which also applies to project browser. The below prompts user to select from browser before adding a selection changed event.


The handler filters for the class of FamilySymbol* and shows a dialogue if the result yields more than 0 results.


Note that not every thing in the project browser is a FamilySymbol so ElementType class will cover more aspects such as system families.


You would have to continue execution in the handler and perhaps raise an external event to get an editable document status (I suspect the selection changed event doesn't give you that). 


You can also use e.GetDocument below instead of casting sender 's' to UIApplication to get the Document.


Public Function Obj_220831a(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result
        Dim IntUIApp As UIApplication = commandData.Application
        Dim IntUIDoc As UIDocument = commandData.Application.ActiveUIDocument
        Dim IntDoc As Document = IntUIDoc.Document

        TaskDialog.Show("Select", "Pick family symbol from project browser")
        AddHandler IntUIApp.SelectionChanged, AddressOf SelectionChanged

        Return Result.Succeeded
    End Function

    Public Sub SelectionChanged(s As Object, e As Autodesk.Revit.UI.Events.SelectionChangedEventArgs)
        Dim UIapp As UIApplication = s
        Dim J As ISet(Of ElementId) = e.GetSelectedElements
        Dim J0 As List(Of ElementId) = J.ToList

        Dim FEC As New FilteredElementCollector(UIapp.ActiveUIDocument.Document, J0)
        Dim F0 As New ElementClassFilter(GetType(FamilySymbol))
        Dim Els As List(Of Element) = FEC.WherePasses(F0).ToElements

        If Els.Count > 0 Then
            TaskDialog.Show("Selection", Els(0).Name)
            RemoveHandler UIapp.SelectionChanged, AddressOf SelectionChanged
        End If
    End Sub






Message 4 of 7
in reply to: RPTHOMAS108

Thanks for your reply. In your opinion, what would be a workflow that is more common?

Message 5 of 7
in reply to: grubdex

It really depends on what your add-in is being used for i.e is it modal or modeless interaction is it working with a few categories of elements or many?


It is often the case you have to create dialogues that replicate the ones Revit inherently has which is a bit annoying but doesn't take that long with WPF for something such as FamilySymbol selection. That would allow a modal interaction.


You aim to stay within the IExternalCommand context in a modal way to start with but if that isn't possible then you have to get back into a similar context via raising ExternalEvents from modeless forms etc. There are also other methods of obtaining a valid context to work with.



Message 6 of 7
in reply to: RPTHOMAS108

Thanks for the answer!


Do you happen to have any pointers or examples of how to develop modeless forms with the Revit API by chance? Would be much appreciated, thanks!

Message 7 of 7
in reply to: grubdex

There are samples in the SDK:



It is for Windows Forms but same approach would be used for WPF.

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

Post to forums  

Autodesk Customer Advisory Groups

Rail Community