retrieving type id based on family name

retrieving type id based on family name

Anonymous
Not applicable
2,389 Views
3 Replies
Message 1 of 4

retrieving type id based on family name

Anonymous
Not applicable

I have to retrieve the type id (typically returned by Element.getTypeId()). The only info I have is a family name and there does not have to be an instance loaded into the project.

 

I manage to find the family (at least that's what I think I'm getting) by the following code

 

List<Element> families = new List<Element>(
                new FilteredElementCollector(doc)
                .OfClass(typeof(Family))
                .Where<Element>(e => e.Name.Equals(search_name)));

but when I then try the following code it just returns a type id with value -1

families[0].GetTypeId()

I think this is mainly due to my lack of understanding of revit but no amounts of google searches seems to bring me any closer to a solution to this, it shouldn't be that hard right?

0 Likes
Accepted solutions (1)
2,390 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
What do you need the type ID for?
0 Likes
Message 3 of 4

Anonymous
Not applicable

I need it in order to call the Element.changeTypId(ElementId) method under some circumstances.

 

Up until now I've had full control over the type ids of the elements used in our projects so I was simply able to maintain a .txt file with them but now the only thing I know is the name of the family. The image below shows how it can typically look like in revit.

Capture.PNG

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

Finally solved it thanks to this article by Jeremy

 

My code to retrieve the type id:

FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(Family));
Family family = collector.FirstOrDefault<Element>(e => e.Name.Equals(search_name)) as Family;
ElementId new_type_id = family.GetFamilySymbolIds().ElementAt(0);