Finding the Family name of elements using python

As the title says I’m trying to find the Family name of elements using Python.

As an input I have a list of quite a lot of elements, both pipes and pipe fittings. I only really need to know the name of the pipe fittings (for the pipes, I just need to know that they’re pipes).
Currently, when I run them through a simple Name node (or bit in a code block, really) I’m getting the names of the family types, I can find the Type, Family and then the Family name of the pipe fittings, but the problem is that pipes will be going through the same process and that will cause errors.
I have considered splitting them up, giving them their seperate process while keeping track of their indices, and then putting them back together, but I thought there should be a more elegant solution.

I can use Python rather well for the sake of list logic and calculation, but trying to use it to read data straight from Revit is still something I don’t understand (if anyone knows a good guide on information about that interation I’d be very grateful), so I’m asking here. The only thing I really need is getting the name of one element, and I can create the rest of the code myself.

Thanks in advance!

Not answering your question but this resource should be the bible for any budding Python user wanting to learn how to apply it to the Revit API:

1 Like

Also, if this really is all you need it is a very simple bit of code as the ‘Name’ of an element is a default property of any element.

Simple unwrap your pipes and call the property as below, ensuring you have the right imports. I’ll let you have a go at working out which you need P.S. you can find an overview of the boilerplate code in that nifty resource I linked above

pipes = UnwrapElement(IN[0])

pipe_name = [p.Name for p in pipe] 

OUT = pipe_name 
1 Like

I think we’re almost there but:

I am looking for the name of the Family, not the Family Type.

Unfortunately having technical issues so cant open Revit to have a look at how to achieve this for you but have a look on this forum post:

Seems to be doing something very similar to what you’re trying to achieve

1 Like

That definitely helped me get to the solution:

import clr
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

elelist = UnwrapElement(IN[0])

for ele in elelist:
		type_id = ele.GetTypeId()
		ele_type = doc.GetElement(type_id)
		ele_fam = ele_type.Family
		ele_name = ele_fam.Name

OUT = outlist

Thanks a lot!

1 Like