How to access family type of any instance?

How to access family type of any instance?

theknownsilhouette
Enthusiast Enthusiast
559 Views
6 Replies
Message 1 of 7

How to access family type of any instance?

theknownsilhouette
Enthusiast
Enthusiast

How can I access the name of family type used for any instance? I have a family of window named as "Fixed_1X" which further has family types as shown in below snap.

theknownsilhouette_0-1671108995589.png

 

How can I access name of the family type for any family instance. I want to retrieve a string "Window_Fixed 2850" for this example. Any suggestions @jeremytammik @naveen.kumar.t @RPTHOMAS108 @architect.bim ?


I'm getting name of the FamilySymbol (Fixed_1X) using below syntax.

string symbolName = (element as FamilyInstance).Symbol.Name; 

 

When I try below syntax familyTypeName returns "FamilySymbol".

string familyTypeName = (defaultWindow as FamilyInstance).Symbol.GetType().Name;

 

0 Likes
Accepted solutions (1)
560 Views
6 Replies
Replies (6)
Message 2 of 7

ridaabderrahmane
Enthusiast
Enthusiast

string familyTypeName = document.GetElement((defaultWindow as FamilyInstance).Symbol.GetTypeId()).Name;

 

0 Likes
Message 3 of 7

RPTHOMAS108
Mentor
Mentor

Best way to resolve these kinds of questions is to use RevitLookup and work back from there.

 

If you want the name of the FamilySymbol you get the FamilySymbol from the document via it's id (FamilyInstance.GetTypeId). That object then has a name.

 

You can likely also get it via parameters on the instance.

 

Stringing long lines together with dots is not the best way to understand what you are getting at each stage e.g.

string familyTypeName = document.GetElement((defaultWindow as FamilyInstance).Symbol.GetTypeId()).Name;

 

In the above the member GetTypeId is available at Element level of inheritance and when you use Element.GetTypeId it will return the id of the ElementType for that Element.

 

Also FamilyInstance.Name often reflects its FamilySymbol.Name anyway so I'm not seeing the complication here perhaps? It is harder to get FamilyName directly (FamilySymbol.Family.Name). However you say you are getting 'Fixed_1X' that is the name of your Family in the above UI image.

0 Likes
Message 4 of 7

theknownsilhouette
Enthusiast
Enthusiast

I've already tried it with Revit lookup but couldn't navigate the name of the family type . I can access the family name but I couldn't access the name of family type for any specific instance placed in model. I'm trying to access the family type name i.e. "Window_Fixed 2850" in this case.

theknownsilhouette_1-1671126000593.png

 

0 Likes
Message 5 of 7

RPTHOMAS108
Mentor
Mentor
Accepted solution

To start with what are you filtering for, what elements are you starting out with:

Family, FamilyInstance or FamilySymbol?

 

ProjBrowser.png

FamilySymbolFamilySymbol

FamilyInstanceFamilyInstance

FamilyFamily

Pick an instance of the object use 'Snoop current selection' (that is a FamilyInstance).

 

Scroll down to and select GetTypeId (that brings up the FamilySymbol)

 

Scroll down to and select Family (that brings up the Family).

 

Note that when you select GetTypeId in RevitLookup it is doing some work on your behalf in terms of getting the FamilySymbol from the id returned by this method.

 

0 Likes
Message 6 of 7

theknownsilhouette
Enthusiast
Enthusiast

1. I got a List<Element> (windowsOnTheLevel) using FilteredElementCollector.
2. Element defaultWindow = windowsOnTheLevel.FirstOrDefault();
3. FamilyInstance instance = defaultWindow as FamilyInstance;
4. FamilySymbol famSymbol = instance.Symbol;
5. string type_ = instance.Symbol.Name;

0 Likes
Message 7 of 7

RPTHOMAS108
Mentor
Mentor

Yes that's fine, as I noted earlier the name of the FamilySymbol and that of the FamilyInstance is likely the same. So you could have stopped at FamilyInstance or even by just getting the Name from the Element directly out of the collector.

 

FamilyInstance.Symbol is a helper property but you get the same result from: Document.GetElement(Element.GetTypeId) and that works more generically i.e. for system families such as Walls.

 

Understanding the inheritance used in the API especially those classes derived from ElementType will allow you to avoid writing different versions of code that does the same thing for different objects e.g. the read/write property FamilyInstance.Symbol is equivalent to Element.GetTypeId and Element.ChangeTypeId, I'm unsure that there is benefit in using it therefore (beyond convenience).

0 Likes