Menu creation and populating the menu with data

Hello everyone. I need that when the button is pressed, a window will fly out that I could fill with families. As far as I understand, i need to connect the databases here? Where can I read about it?

Hi Andrey,
heavily based on the save family button in pyRevit, it goes like this:

# Jean-Marc Couffin, June 2021

# -*- coding: utf-8 -*-

from pyrevit import revit, forms

doc = revit.doc

family_dict = {}

for family in revit.query.get_families(revit.doc, only_editable=True):

    if family.FamilyCategory:

        family_dict[

            "%s: %s" % (family.FamilyCategory.Name, family.Name)

        ] = family

if family_dict:

    selected_families = forms.SelectFromList.show(

        sorted(family_dict.keys()),

        title="Select Families",

        multiselect=True,

    )

    if selected_families:

        for idx, family in enumerate([family_dict[x] for x in selected_families]):

            print (family.Name)
            
            print (family)
            # or do whatever

you can find a long documentation here:
https://pyrevit.readthedocs.io/en/latest/pyrevit/forms.html

and some easier to understand examples here:
https://pyrevit1.readthedocs.io/en/latest/outputfeatures.html

Thanks Jean-Marc. And where should I keep the families themselves? I do not quite understand the logic of work.

you need to be more precise about what you expect to achieve and what you have done so far.
no help comes totally free :slight_smile:

I wanted to clarify, where do I need to store families? This can be done, through the pyrevit, or through the WPF with the connection of the SQL tables?
P.S. “no help comes totally free :slight_smile:
how much does help cost today?

effort on your side :grin:

explain what you are trying to do or achieve with the script you are building.
most of the time you don’t need a database to do your things in revit with pyRevit

At the moment, an empty window, which I created following the example. I need to make an element library out of it

you want to list specific families? which ones? the ones from the active view?

Did you try the code block I provided?

You could replace the get_family(revit.doc, only_editable=True) by a get_all_elements_in_view(view)

you will therefore grab all elements in the view and then you need to work you way to the family with something like:

type_id = e.GetTypeId()
element_type = doc.GetElement(type_id)
family = element_type.Family
name = family.Name

quick and dirty for the sake of the exercise:

# Jean-Marc Couffin, June 2021

# -*- coding: utf-8 -*-

from pyrevit import revit, forms

doc = revit.doc

active_view = doc.ActiveView

family_dict = {}

for e in revit.query.get_all_elements_in_view(active_view):

    try:

        e_type = revit.query.get_type(e)

        family = e_type.Family

        if family.FamilyCategory:

            family_dict[

                "%s: %s" % (family.FamilyCategory.Name, family.Name)

            ] = family

    except:

        pass

if family_dict:

    selected_families = forms.SelectFromList.show(

        sorted(family_dict.keys()),

        title="Select Families",

        multiselect=True,

    )

    if selected_families:

        for idx, family in enumerate([family_dict[x] for x in selected_families]):

            print (family.Name)

            print (family)

this is how it turns out