Results 1 to 2 of 2

Thread: Filtering for all instances, of all types, of a particular family.

  1. #1
    100 Club
    Join Date
    2006-07
    Posts
    130
    Login to Give a bone
    0

    Default Filtering for all instances, of all types, of a particular family.

    [Disclaimer:C# and Revit API Newbie) Here's what I'm trying to do:

    A. Iterate through all instances of the "Weld Symbol" family. (I want to iterate *all* types, which will include "Bottom," "Top," "Both," and "None")

    B. (Assuming I've located the first instance) temporarily store the values for a number of the instance's parameters.

    C. Replace the instance with the same type from the "Weld Symbol (MKA)" family. I want to do this programmatically, because if I do it by simply doing a "Select all instances" command, the parameter settings all get removed.

    D. Set the now-reset parameters with the stored parameter values

    E. Move on to the next instance.




    From locating and trying many examples, below is the code I've gotten to work so far. Obviously, it only locates instances named "Top" from ANY family.

    Code:
     
                   string prompt;
    
                    //Get the application
                    UIApplication uiApp = commandData.Application;
    
                    //Get the document
                    Document doc = uiApp.ActiveUIDocument.Document;
    
                    //Create a filtered element collector based on the document
                    FilteredElementCollector collector = new FilteredElementCollector(doc);
    
                    //Set the collector to look for a particular class
                    collector = collector.OfClass(typeof(FamilySymbol));
    
                    //var query = from element in collector where element.Name == "Bottom" select element;
                    var query = from element in collector where element.Name == "Top" select element;
    
                    //Create a list from the query
                    List<Element> famSyms = query.ToList<Element>();
    
                    //Get the element ID of the first family symbol
                    ElementId symbolId = famSyms[0].Id;
    
                    //Create a new filter to look for elements matching the element ID
                    FamilyInstanceFilter filter = new FamilyInstanceFilter(doc, symbolId);
    
                    //Reset the collector?????????????????
                    collector = new FilteredElementCollector(doc);
    
                    //Create an indexed collector of element type instances which pass the symbolId filter
                    ICollection<Element> familyInstances = collector.WherePasses(filter).ToElements();
    
                    //Report the number of family type instances found
                    prompt = "Count = " + Convert.ToString(familyInstances.Count);
                    TaskDialog.Show("Revit", prompt);

    And, my questions are:

    1. (Step A, above) How do I filter for all instances of a particular family?

    2. Any suggestions how to proceed with Steps B, C, D, and E? (Please see disclaimer at the top of the post) LOL

    3. In my code, what is the need for the step reading "collector = new FilteredElementCollector(doc);?"


    Thanks, in advance, for your help and suggestions.

  2. #2
    100 Club
    Join Date
    2006-07
    Posts
    130
    Login to Give a bone
    0

    Default Re: Filtering for all instances, of all types, of a particular family.

    C'mon, now. I *know* this is an easy question for you skilled programmers out there. Can you help this newbie out a bit?

Similar Threads

  1. Schedule group instances - multifamily unit types
    By rum718 in forum Revit Architecture - General
    Replies: 9
    Last Post: 2015-02-12, 04:24 PM
  2. Replies: 11
    Last Post: 2012-12-14, 09:29 PM
  3. 2012: Ghost Types: "Select all in project (empty) ... 31 instances will be deleted"
    By Duncan Lithgow in forum Revit Architecture - General
    Replies: 3
    Last Post: 2012-09-26, 01:26 PM
  4. MEP Utilities in Revit Family Types (Instances?)
    By am4soft in forum Revit Architecture - Families
    Replies: 1
    Last Post: 2009-10-08, 02:06 AM
  5. Family instances HELP
    By comical_wenger in forum Revit Architecture - General
    Replies: 2
    Last Post: 2009-07-10, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •