1

I need a code that when I click on my Revit add-in button returns me the family of the model element that is selected. Anyone can help with this?

I did some research in Autodesk University and I couldn't find something easy to understand that make something near of this

MackMag
  • 23
  • 4

1 Answers1

0

Do you mean:

var selElementId = uidoc.Selection.GetElementIds().FirstOrDefault();
var selElement = doc.GetElement(selElement);
var elemType = doc.GetElement(selElement.GetTypeId()) as ElementType;
var famName = elemType.FamilyName;

var fam = new FilteredElementCollector(doc)
    .OfClass(typeof(Family))
    .Where(f => f.Name == famName)
    .FirstOrDefault() as Family;

there might be better solutions, but this should also do the trick

Vahdet
  • 43
  • 8