System Families Filter and Beach Aerial Picture.

By Jaime Rosales 

Saying hello from my home country Guatemala, where I’m one week away from getting married, but that doesn’t stop me from continuing my passion for aerial photography. Here is a picture I took over the weekend with my drone “the toy” and my Hero 3+ GoPro at the Pacific Ocean beach in Guatemala.

 DCIM100GOPRO

Back to Revit API, this week one that caught my eye came from the Autodesk Community Forum, from one of our distinguished contributors.

Question:” Is it possible to filter just for System Families and ignore Component Families? I have used this example, however despite the heading, it actually returns all families.

http://adndevblog.typepad.com/aec/2012/05/accessing-system-families-in-a-revit-template.html

I know that I can filter by a specified Type:

FilteredElementCollector coll = new FilteredElementCollector(pDoc);    // get all the wall types as wall type objects:     coll.OfClass(typeof(WallType));    IEnumerable<WallType> types = coll.Cast<WallType>();

What I need is to return all Types that are System Families. Any and all suggestions appreciated; I have Googled to a standstill.”

The Answer came from our Revit API Engineering Team.

Answer: Sure – try .WhereElementIsElementType() plus new ElementClassFilter(typeof(FamilySymbol), true /* inverted */)

You can apply these two sequentially and that should get what they asked for.

Followed by that answer I tried a small piece of code to check how to get back what our customer was asking for.

[Transaction(TransactionMode.Manual)]public class Command : IExternalCommand{public Result Execute(  ExternalCommandData commandData,  ref string message,  ElementSet elements)  {    UIApplication uiapp = commandData.Application;    UIDocument uidoc = uiapp.ActiveUIDocument;    Application app = uiapp.Application;    Document doc = uidoc.Document;     // WhereElementIsElementType is pretty self explanatory      // since it will give back only elements that are ElementType    FilteredElementCollector coll = new FilteredElementCollector(doc)                                        .WhereElementIsElementType();    // the true value after the typeof will give back the     // inverted of what it was asked    ElementClassFilter filterInv =                    new ElementClassFilter(typeof(FamilySymbol), true);    // add a watch to coll.WherePasses(filterInv) when debugging,     //when the result is checked every inverted FamilySymbol will     //get displayed.    coll.WherePasses(filterInv);     return Result.Succeeded;  }}

The Result of coll.WherePasses(filterInv); when is added to Watch in debug will give you back a list of all the Types that are ElementType and inverted from what the Component Families will return you.


Comments

2 responses to “System Families Filter and Beach Aerial Picture.”

  1. Jaime, I am guessing that you are on your honeymoon now, so probably not checking your blog (I hope). This worked perfectly thank you. I have to admit to being unclear as to how to implement the comment from Revit API Engineering Team, so your additional information helped a lot. I will update the original Forum page. Regards, Dale

  2. Hi Dale,
    Glad to hear I was able to clarify the unclear part, and that it worked for you.
    Cheers,
    Jaime

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading