Get FamilySymbol from Elements in ActiveView

Get FamilySymbol from Elements in ActiveView

luisdavid.mena
Enthusiast Enthusiast
2,174 Views
8 Replies
Message 1 of 9

Get FamilySymbol from Elements in ActiveView

luisdavid.mena
Enthusiast
Enthusiast

Hello
I'm trying to get FamilySymbol from an active 3D View using FilteredElementCollector. But I'm getting null values.

FilteredElementCollector elements = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_StructuralFoundation);

Attached is the screenshot of the elements(StructuralFoundation) that I'm trying to get.
Any help would be very appreciated.

0 Likes
Accepted solutions (1)
2,175 Views
8 Replies
Replies (8)
Message 2 of 9

RPTHOMAS108
Mentor
Mentor

FamilySymbols are an ElementType and as such don't appear in the view themselves.

 

Filter instead for FamilyInstances then from there use Element.GetTypeId on the resulting elements.

 

Could also use FamilyInstance.Symbol if you've cast the elements returned from the filter to FamilyInstance.

 

 

Message 3 of 9

ridaabderrahmane
Enthusiast
Enthusiast
FilteredElementCollector familySymbols = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_StructuralFoundation).Cast<FamilyInstance>().Select(e=>e.Symbol).ToList():;
0 Likes
Message 4 of 9

guillain.jolivet
Contributor
Contributor

I'm actually working on something like that and didn't find out how to do it with just a FilteredElementCollector...

 

So far, I find every single type name of structural foundation in the view, then i collect every StructuralFoundation element type in the document and iterate it and compare the ElementType name with type names i found in the view. And add it to a new list.

 

List<string> object_types_in_view = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_StructuralFoundation).WhereElementIsNotElementType().ToElements().Select(el => el.Name).Distinct().ToList();

object_types_in_view.Sort();

ICollection<Element> object_types = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFoundation).WhereElementIsElementType().ToElements();

List<ElementType> Types_in_view = new List<ElementType>();

foreach (ElementType el_ty in object_types)
{
    if (object_types_in_view.Contains(el_ty.Name))
    {
        Types_in_view.Add(el_ty);
    }
}

 

 It's maybe not the best way to achieve it but it works!

0 Likes
Message 5 of 9

RPTHOMAS108
Mentor
Mentor
Accepted solution

If you incorporate GetTypeId you can avoid dealing with strings:

 

IList<ElementId> object_typeIds_in_view = new FilteredElementCollector(IntDoc, IntDoc.ActiveView.Id)
				.OfCategory(BuiltInCategory.OST_StructuralFoundation)
				.WhereElementIsNotElementType()
				.ToElements().Select(el => el.GetTypeId()).Distinct().ToList();

IList<Element> object_types_in_view 
     = new FilteredElementCollector(IntDoc, object_typeIds_in_view)						 
                .WhereElementIsElementType().ToElements();

 

Message 6 of 9

luisdavid.mena
Enthusiast
Enthusiast
Thank you !
But I don't want a list by every instance. What I need is a list of the existing types in the model. 😞
0 Likes
Message 7 of 9

guillain.jolivet
Contributor
Contributor

@luisdavid.menaI don't understand. Both solutions give you family types existing in the active view. It's not what you are looking for?

0 Likes
Message 8 of 9

luisdavid.mena
Enthusiast
Enthusiast

@ridaabderrahmane , @guillain.jolivet@RPTHOMAS108  . Thank you for your help but I'm still getting null values.

This is what I'm trying inside a Macro:

 

//Get Document
Document doc = this.ActiveUIDocument.Document;
UIApplication uiapp = new UIApplication(Application);
UIDocument uidoc = this.ActiveUIDocument;
//FOUNDATION TYPES
IList<ElementId> object_typeIds_in_view = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_StructuralFoundation).WhereElementIsNotElementType().ToElements().Select(el=>el.GetTypeId()).Distinct().ToList();
IList<Element> object_types_in_view = new FilteredElementCollector(doc, object_typeIds_in_view).WhereElementIsNotElementType().ToElements();
//Show result
string message;
message = "Name of Types : ";
foreach(Element elem in object_types_in_view)
	message += "\n" + elem.Name;
TaskDialog.Show("Result","Number of elements : " + object_types_in_view.Count() + "\n" + message);

 

Also the taskDialog within my model, which is a Central Model, not linked models.

0 Likes
Message 9 of 9

luisdavid.mena
Enthusiast
Enthusiast

Hello. I'm sorry. It was just that in the second collector I used WhereElementIsNotElementType() instead of WhereElementIsElementType() 😮 
The topic is solved ! 

Thank you