Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hierarchies from Elements

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
760 Views, 4 Replies

Hierarchies from Elements

I'm scripting a method to get the hierarchy of a selected elemented in the Revit API.  The script below is setup in Python and is currently working with the Revit sample files:

 

ParamListCategory=elem.GetParameters("Category")
ParamValue=ParamListCategory[0].AsValueString()

ParamListType=elem.GetParameters("Type")
ParamValue=ParamListType[0].AsValueString()

 

My concern is that this method may not work with all revit projects.  Can anyone offer information regarding element hierarchy data as a parameter?  In other words, do all Revit files have parameters for Category, Family, Type, etc.?  Or are these parameters only accessible as of a certain version of Revit?  The reason I ask: I would like to develop a tool which can work on any project, and want to be sure I'm using the best method to extract hierarchy data from an element.


Thanks for any help!

 

4 REPLIES 4
Message 2 of 5
jeremytammik
in reply to: Anonymous

Dear Erick,

 

This all looks rather strange to me.

 

I would suggest using the Element Category property and GetTypeId method instead of the parameters.

 

If you would insist on using parameters, I would urge you not to use the language dependent name to access them, but a built-in parameter enumeration value instead, and not read them as value string but process their true raw content.

 

Furthermore, as you can see from your own code, you might retrieve multiple parameters with the same name, and you are arbitrarily choosing ton use the first.

 

Tsk, tsk.

 

The property and method access are guaranteed to give you what you expect and are implemented on absolutely all Revit database elements.

 

Both of them may return null or an invalid element id, of course, so you need to take that into account.

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5
Anonymous
in reply to: jeremytammik

Thanks Jeremy. I used the two lines you suggested:

 

elem=doc.GetElement(selection.UniqueId)
elemType=doc.GetElement(elem.GetTypeId())
OUT.Add(elem.Category.Name) OUT.Add(elemType)

 

In this case I'm getting decent results (screenshot below).  The item for elemType gives Type and Family, and I want to separate the two. Could you advise the most appropriate way to parse out Family and Family Type from the element?  My goal is to extract the entire hierarchy from any selected Revit element (Category, Family, Type) in the most efficient way possible.  I'll have to accommodate elements which don't have family, types, and categories as well.

 

2014-10-07 09_36_31-Dynamo.jpg

Message 4 of 5
jeremytammik
in reply to: Anonymous

Dear Erick,

 

Thank you for your update and appreciation.

 

Congratulations on moving forward with this and getting decent results now. I am glad it helped.

 

Again, I find your question somewhat hard to comprehend, given that we appear to be talking from totally different points of view.

 

Anyway, just taking you by your words, "the most appropriate way to parse out Family and Family Type from the element", I would say:

 

The most appropriate, easy and efficient way to obtain the family and family type from an element, i.e. a family instance, in this case, would be to query its FamilySymbol -- that corresponds to the family type -- and from that the parent family:

 

  Element e;
  FamilyInstance fi = e as FamilyInstance;
  FamilySymbol symbol = fi.Symbol;
  Family = symbol.Family;

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 5
Anonymous
in reply to: jeremytammik

Jeremy,

 

Thanks for your help on this and my apologies for the late reply.  The tips you've given so far have been really helpful, but they do not work on system families.  In short, I'm trying to use a better method for filtering through an entire project and extracting the category, family, and type of every element in the project.  Here's a post on the project: http://modelab.is/revit-treemap/

 

As of now, I'm thinking I have to test every system family for its type and then use specific syntax like "WallType" for each system family.  Is there a simpler method for extracting this information from every element?  

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community