Define and export relationships between shared nested families

Hello everyone,

We need to define and export relationships between shared nested families. We haven’t found a way built into Revit for defining such relationships and we are missing some steps for creating a custom solution. Below is our current state of investigation. It seems fairly complicated, so I tried to be as precise as possible. Perhaps there is a much easier way?

Let’s assume the following:

  • in a Revit model there is a family F1 and a shared family F2
  • two instances of F2 are nested into F1; let’s call them F2_I1 and F2_I2
  • in the family context (FC) of editing F1, let’s call the element IDs of the two F2 instances: FC_ID(F2_I1) and FC_ID(F2_I2)

An example of F1 would be a folding shower door with the two F2 instances being the panels.

Let’s further assume that when defining F1 we want to specify relationships between its shared nested family instances and either other shared nested family instances or F1. Example: that F2_I2 and F2_I1 are related and that F2_I1 and F1 are related.

We can do that by adding a “related-to” instance parameter to the F2 family and storing in it the element ID of the related family. Note: it may be wrong to use an instance parameter here - we are not sure about this.

The point here is to define the relationships with the IDs that exist in the family definition, as opposed to the IDs that exist in the family instances in the Revit model. The former should be the same for all instances while the latter change from one instance to another.

In particular, for every ID stored in a related-to parameter there are as many different IDs in the model as there are instances of the respective family.

The Dynamo challenge is to look up the ID-relations in the family definition and to translate them into ID-relations in the model.

A first question is what the element IDs in the family context really are. When using them in the model with “Manage–>Select by ID” Revit complains the ID is invalid. When using them in the family editor, the respective element gets selected, as expected. I assume this means that a model and families within this model have separate ID scopes. Right?

Let’s further assume there are two instances of family F1 in the model. Let’s call them F1_I1 and F1_I2. Let’s say we want to create a list of the IDs of the shared nested family instances and the IDs of the elements they are related to.

There are four nested family instances, let’s call them: F1_I1.F2_I1

Note that in the model context, obviously, the element IDs of the F2_I1 and F2_I2 instances are different for the two F1 instances. They are also different from the element ID of the F2_I1 instance of the family F1.

My idea would be:

  1. iterate over all instances of family F1
  2. iterate over the nested F2 family instances within F1 (e.g. using FamilyInstance.SubComponents from Clockwork).
  3. get the family of the respective shared nested family instance
  4. determine FC_ID(F2_Ix), i.e. the element ID of the F2 family instance in the context of the family definition.
  5. look up the element ID stored in the related-to parameter
  6. determine the F2 family instance F2_Iy contained in the same F1 family instance for which FC_ID(F2_Iy) is this element ID
  7. store the element IDs MC_ID(F2_Ix) and MC_ID(F2_Ix) for export, i.e. the element IDs in the model context of the related elements

Steps 1-3, 5 and 7 are simple. We currently have no idea how to do steps 4 and 6.

Many thanks!