The previous scenario discussed the manual selection of family instances or other elements using either pre- or post-selection. What if you want to automatically select and modify all instances of a specific type?

This time around, the family that we are driving is more complex, consisting of a kitchen cabinet making use of nested families defining different door styles.

For the modification, we pick a modification of the door style, i.e. a modification of a nested type, which is identified by the element id of the corresponding family type.

The third and final sample command in this series demonstrating use of the family API in the project context is CmdKitchenUpdate.
It is designed to be launched in a model representing a kitchen design.
It determines all applicable door panel types, automatically selects all kitchen cabinets, displays their current door style, prompts for a new one, and sets the selected type to all cabinets.

Retrieving Specific Family Symbols

The first step in this process is to determine all the available and applicable door panel types.

As always, we make use of a filtered element collector.
In this case, we need to retrieve family symbols of the generic model category.
To identify the door panel types, we post-process the results using a generic LINQ Where method checking for element names beginning with the substring "Door Panel - " like this:

Display Available Door Panel Types

The retrieval of the available door panel types and the casework elements to apply them to from the database actually constitute the main tasks in this command.

The remainder is pretty trivial:

Display the current door panel type setting, or '*VARIES*', if several are in use.

Display a list of all available door panel types and prompt the user to select one.

Apply the selected type to all cabinet elements.

The two display tasks are handled by the following simple .NET form:

The form stores the list of door panel element types that it receives as an input argument to its constructor as its combo box data source, and displays the Name property of these elements as the combo box selection entries, which leads to an extremely compact and effective implementation.

Furthermore, the selected item can be returned directly as the Revit database element it is:

Modifying a Nested Family Type

Once the form has been displayed and the user has made her selection, applying the selected door panel type to the cabinet instances is achieved by simply setting the door panel type parameter value to the selected type element id, obviously requiring a transaction:

Conclusion and Download

Ok, I think I finally covered just about everything I have to say about this.
Although some points could bear further elaboration...

I am happy with this very pure implementation.

I am a bit surprised that it took three extensive blog posts to cover the material that I presented live in Moscow in less than fifteen minutes.
I hope it is useful and appreciated.

For the sake of completeness, here is a slightly updated archive file
FamilyApi10.zip containing
the complete source code, Visual Studio solution and add-in manifest for this sample, plus the
table family RFA and
kitchen model RVT to
experiment with.

Focus!

Before closing, let me add a pointer to a self-evident aspect of work and time management that we have all heard far too many times and yet bears repeating once again:

A
surprisingly simple productivity secret is
to identify priorities and then give yourself some time to focus completely on the task at hand for a while, removing all distractions, in particular switching off interruptions such as email and messages for a while.

How many times will I have to continue hearing that message before it finally sinks in?