Family documents provide access to the FamilyManager property. The FamilyManager class provides access to family types and parameters. Using this class you can add and remove types, add and remove family and shared parameters, set the value for parameters in different family types, and define formulas to drive parameter values.
The FamilyManager can be used to iterate through the types in a family, as the following example demonstrates.
Code Region 13-11: Getting the types in a family |
public void GetFamilyTypesInFamily(Document familyDoc) { if (familyDoc.IsFamilyDocument == true) { FamilyManager familyManager = familyDoc.FamilyManager; // get types in family string types = "Family Types: "; FamilyTypeSet familyTypes = familyManager.Types; FamilyTypeSetIterator familyTypesItor = familyTypes.ForwardIterator(); familyTypesItor.Reset(); while (familyTypesItor.MoveNext()) { FamilyType familyType = familyTypesItor.Current as FamilyType; types += "\n" + familyType.Name; } MessageBox.Show(types, "Revit"); } } |
Figure 53: Family types in Concrete-Rectangular-Column family
FamilyManager provides the ability to iterate through existing types in a family, and add and modify types and their parameters.
The following example shows how to add a new type, set its parameters and then assign the new type to a FamilyInstance. Type editing is done on the current type by using the Set() function. The current type is available from the CurrentType property. The CurrentType property can be used to set the current type before editing, or use the NewType() function which creates a new type and sets it to the current type for editing.
Note that once the new type is created and modified, Document.LoadFamily() is used to load the family back into the Revit project to make the new type available.
Code Region 13-12: Editing Family Types |
public void EditFamilyTypes(Document document, FamilyInstance familyInstance) { // example works best when familyInstance is a rectangular concrete element if (null != familyInstance.Symbol) { // Get family associated with this Family family = familyInstance.Symbol.Family; // Get Family document for family Document familyDoc = document.EditFamily(family); if (null != familyDoc) { FamilyManager familyManager = familyDoc.FamilyManager; // add a new type and edit its parameters FamilyType newFamilyType = familyManager.NewType("2X2"); // look for 'b' and 'h' parameters and set them to 2 feet FamilyParameter familyParam = familyManager.get_Parameter("b"); if (null != familyParam) { familyManager.Set(familyParam, 2.0); } familyParam = familyManager.get_Parameter("h"); if (null != familyParam) { familyManager.Set(familyParam, 2.0); } // now update the Revit project with Family which has a new type family = familyDoc.LoadFamily(document); // find the new type and assign it to FamilyInstance FamilySymbolSetIterator symbolsItor = family.Symbols.ForwardIterator(); symbolsItor.Reset(); while (symbolsItor.MoveNext()) { FamilySymbol familySymbol = symbolsItor.Current as FamilySymbol; if (familySymbol.Name == "2X2") { familyInstance.Symbol = familySymbol; break; } } } } } |