PDA

View Full Version : 2012 How to retrieve instance parameters from an uninstantiated (uninserted) family



some buddy
2013-05-17, 07:02 PM
Hi,

I am faced with two situations described below.

I have a project where I need to click on an element (family) inserted in a Revit legend (the family could or could not be used (inserted/instantiated) in the project (model), and then list the parameters attached to that element.

I know how to retrieve FamilyInstance, FamilySymbol and Family parameters from a family which is used (inserted/instantiated) in the project (model):



ElementClassFilter FamilyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
FilteredElementCollector FamilyInstanceCollector = new FilteredElementCollector(dbDoc);
ICollection<Element> AllFamilyInstances = FamilyInstanceCollector.WherePasses(FamilyInstanceFilter).ToElements();

// Iterate through all FamilyInstances
foreach (FamilyInstance FamInst in AllFamilyInstances)
{
Fam = FamInst.Family;
FamSymb = FamInst.Symbol;

// Family parameters from Family
foreach (Parameter FamParam in Fam.Parameters)
{
string ParamName = FamParam.Definition.Name;
}

// Symbol parameters from the inserted symbol
foreach (Parameter SymbParam in FamSymb.Parameters)
{
string ParamName = SymbParam.Definition.Name;
}

// Instance parameters from FamilyInstance
foreach (Parameter FamInstParam in FamInst.Parameters)
{
string ParamName = FamInstParam.Definition.Name;
}
}

On the other hand, I know that it IS possible to assign instance parameters to a family in edit mode, and even if the family is not used in the project afterwards, these instance parameters "live" in that family, but I don't know how to retrieve these instance parameters from a family which is NOT used (inserted/instantiated) in the project:



Autodesk.Revit.DB.FilteredElementCollector FilteredCollector = new Autodesk.Revit.DB.FilteredElementCollector(dbDoc);
ICollection<Autodesk.Revit.DB.Element> FamilyCollection = FilteredCollector.OfClass(typeof(Autodesk.Revit.DB.Family)).ToElements();

// Iterate through all loaded Families
foreach (Family ColFam in FamilyCollection)

// Family parameters from Family
foreach (Parameter FamParam in ColFam.Parameters)
string ParamName = FamParam.Definition.Name;
}

// Iterate through all family symbols of the curent family (because no one is inserted in the project)
// They should have all the same parameters, but I parse all of them just for the sake of it.
foreach (FamilySymbol FamSymb in ColFam.Symbols)
{
FamilySymbol NewSymbol = FamSymb;

// Symbol parameters of the currently iterated symbol
foreach (Parameter SymbParam in NewSymbol.Parameters)
{
string ParamName = SymbParam.Definition.Name;
}
}
// Instance parameters from Family
// I want to access the instance parameters defined in the
// family editor, I kow they are there, I've created them, but...
// ==================================
// ### I DON'T KNOW HOW TO DO IT! ###
// ==================================
}


Could somebody help, please ?

TIA

Budy :?

mmason.65315
2013-05-18, 06:22 PM
Buddy,

The trick to be able to read the default values for instance parameters is to get to the FamilyManager.
The family manager is a whole separate area of the API, with separate classes for FamilyType and FamilyParameter. You can think of it as the API version of the Family Types dialog in the Family Editor.
Getting there involves opening the family as a document, something along the lines of:



if (ColFam.IsEditable)
{
Document familyDoc = mainDocument.EditFamily( ColFam );
FamilyManager manager = familyDoc.FamilyManager;

foreach (FamilyParameter fp in manager.Parameters )
{
// over simplified, but hopefully you get the idea....
if (fp.IsInstance)
{
string instanceValue = manager.CurrentType.AsString( fp );
}
}

// don't forget to close the family when you're done.
familyDoc.Close(false);
}


Good Luck,
Matt

some buddy
2013-05-21, 06:47 PM
Hi Matt,

This is great stuff, now it's working!

These parameters scattered all over the Revit app. make me think sometimes that somebody in charge with the app. architecture, is high on weed most of the time :)

Thanks for the help,

Buddy :)



Buddy