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: 

Get Instances of Given Types

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
895 Views, 2 Replies

Get Instances of Given Types

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);
    }
}

 

 

2 REPLIES 2
Message 2 of 3
rosalesduquej
in reply to: Anonymous

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. 

 



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
Message 3 of 3
Anonymous
in reply to: rosalesduquej

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:

  1. Retrieve all types in category
  2. Retrieve the conditioned types from (1)
  3. Retrieve elements from model  where element belong to (2)

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.

Post to forums  

Rail Community


Autodesk Design & Make Report