Hi everyone,
As the title implies, I have a list of family types which satisfies some conditions as shown in below code
Now, from these types, I would ike to get the instances which have been placed in the model
Please assist me on this issue
Thanks
ElementCategoryFilter category = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming); IList<Element> typeList = new FilteredElementCollector(doc).WherePasses(category).WhereElementIsElementType().ToElements(); IList<ElementId> noMaterialTypes = new List<ElementId>(); <-- How to get instances of these types? foreach (Element type in typeList) { IList<bool> noMaterial = new List<bool>(); ParameterSet paramSet = type.Parameters; foreach (Parameter param in paramSet) { ParameterType parameterType = param.Definition.ParameterType; if (parameterType == ParameterType.Material && param.AsValueString().Equals("<By Category>")) { noMaterial.Add(true); } } if (noMaterial.Contains(true)) { noMaterialTypes.Add(type.Id); } }
Hi everyone,
As the title implies, I have a list of family types which satisfies some conditions as shown in below code
Now, from these types, I would ike to get the instances which have been placed in the model
Please assist me on this issue
Thanks
ElementCategoryFilter category = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming); IList<Element> typeList = new FilteredElementCollector(doc).WherePasses(category).WhereElementIsElementType().ToElements(); IList<ElementId> noMaterialTypes = new List<ElementId>(); <-- How to get instances of these types? foreach (Element type in typeList) { IList<bool> noMaterial = new List<bool>(); ParameterSet paramSet = type.Parameters; foreach (Parameter param in paramSet) { ParameterType parameterType = param.Definition.ParameterType; if (parameterType == ParameterType.Material && param.AsValueString().Equals("<By Category>")) { noMaterial.Add(true); } } if (noMaterial.Contains(true)) { noMaterialTypes.Add(type.Id); } }
Hi Mr. Hoa,
Have you tried using a FilteredElementCollector to retrieve family instances?
var collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
var familyInstances = collector.OfClass(typeof(FamilyInstance))
Another suggestion, have you checked the FamilyInstancesFilter Class? This can be used to find elements that are family instances of the given family symbol.
http://revitapisearch.com/html/ec0bdad7-e213-f22a-94ef-bc0fd96ac641.htm
Check it out, maybe it will help you get through your problem.
Hi Mr. Hoa,
Have you tried using a FilteredElementCollector to retrieve family instances?
var collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
var familyInstances = collector.OfClass(typeof(FamilyInstance))
Another suggestion, have you checked the FamilyInstancesFilter Class? This can be used to find elements that are family instances of the given family symbol.
http://revitapisearch.com/html/ec0bdad7-e213-f22a-94ef-bc0fd96ac641.htm
Check it out, maybe it will help you get through your problem.
Hi Jaime,
Thank you for your prompt advices
I used to try retrieveing instances as your code before but this code can only retrieve instances without conditions, but what i need is to retrieve instances from conditioned family types (including system families).
I also came across your link and revised my code accordingly as below. I is a useful link since I could learn how to retrieve instances in active document with given type ID. However, it somehow only worked with loadable categories (not with system categories). Bug occured when I replace loadable categories with system categories (such as wall, floor, roof, etc.)
From the bug, I understood that it could not retrieve instances from TypeID if types are of system families
Any other suggestions?
Revised Code:
// Retrieve all types in category
ElementCategoryFilter category = new ElementCategoryFilter(BuiltInCategory.OST_Walls); IList<Element> typeList = new FilteredElementCollector(doc).WherePasses(category).WhereElementIsElementType().ToElements();
// Retrieve conditioned types IList<ElementId> noMaterialTypes = new List<ElementId>(); foreach (Element type in typeList) { IList<bool> noMaterial = new List<bool>(); ParameterSet paramSet = type.Parameters; foreach (Parameter param in paramSet) { ParameterType parameterType = param.Definition.ParameterType; if (parameterType == ParameterType.Material && param.AsValueString().Equals("<By Category>")) { noMaterial.Add(true); } } if (noMaterial.Contains(true)) { noMaterialTypes.Add(type.Id); } }
// Retrieve conditioned elements IList<ElementId> familyInstancesList = new List<ElementId>(); foreach (ElementId typeID in noMaterialTypes) { FamilyInstanceFilter filter = new FamilyInstanceFilter(doc, typeID); <-- Bug here (Could not retrieve instances from TypeID ) IList <Element> familyInstances = new FilteredElementCollector(doc).WherePasses(filter).ToElements(); foreach (Element e in familyInstances) { familyInstancesList.Add(e.Id); } } UIDocument uidoc = new UIDocument(doc); uidoc.Selection.SetElementIds(familyInstancesList);
My purpose line:
Step (1) and (2) are easy
Please give me some suggestions so that I can implement the step (3)
Thanks
Hi Jaime,
Thank you for your prompt advices
I used to try retrieveing instances as your code before but this code can only retrieve instances without conditions, but what i need is to retrieve instances from conditioned family types (including system families).
I also came across your link and revised my code accordingly as below. I is a useful link since I could learn how to retrieve instances in active document with given type ID. However, it somehow only worked with loadable categories (not with system categories). Bug occured when I replace loadable categories with system categories (such as wall, floor, roof, etc.)
From the bug, I understood that it could not retrieve instances from TypeID if types are of system families
Any other suggestions?
Revised Code:
// Retrieve all types in category
ElementCategoryFilter category = new ElementCategoryFilter(BuiltInCategory.OST_Walls); IList<Element> typeList = new FilteredElementCollector(doc).WherePasses(category).WhereElementIsElementType().ToElements();
// Retrieve conditioned types IList<ElementId> noMaterialTypes = new List<ElementId>(); foreach (Element type in typeList) { IList<bool> noMaterial = new List<bool>(); ParameterSet paramSet = type.Parameters; foreach (Parameter param in paramSet) { ParameterType parameterType = param.Definition.ParameterType; if (parameterType == ParameterType.Material && param.AsValueString().Equals("<By Category>")) { noMaterial.Add(true); } } if (noMaterial.Contains(true)) { noMaterialTypes.Add(type.Id); } }
// Retrieve conditioned elements IList<ElementId> familyInstancesList = new List<ElementId>(); foreach (ElementId typeID in noMaterialTypes) { FamilyInstanceFilter filter = new FamilyInstanceFilter(doc, typeID); <-- Bug here (Could not retrieve instances from TypeID ) IList <Element> familyInstances = new FilteredElementCollector(doc).WherePasses(filter).ToElements(); foreach (Element e in familyInstances) { familyInstancesList.Add(e.Id); } } UIDocument uidoc = new UIDocument(doc); uidoc.Selection.SetElementIds(familyInstancesList);
My purpose line:
Step (1) and (2) are easy
Please give me some suggestions so that I can implement the step (3)
Thanks
Can't find what you're looking for? Ask the community or share your knowledge.