MackMag
MackMag

Reputation: 23

Revit Addin getting information from model

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

Upvotes: 1

Views: 240

Answers (1)

Vahdet
Vahdet

Reputation: 43

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

Upvotes: 0

Related Questions