Message 1 of 20
Replace a Family instance with another Family Based on Family Instance Parameter Value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am trying to select multiple family instances based on a their name and a certain value of one of their Family parameters, then i want to replace these families Instances with another family.
This can be done by the UI, but the parameter value requirement makes it manual intensive.
In the code below- based on responses in this forum and others - the code executes without any exceptions. But the model does not reflect any changes. the old family is NOT replaced.
I am not sure what i am missing. I have tried the symbol swap method and the ChangeTypeId method, with and without symbol activation, which was suggested in one of the posts, and i don't know what it means.
can someone point me in the correct direction?
public void Execute(UIApplication a)
{
// i removed code for selecting familyinstances and loaded families
#region activate a replacement Symbol of the replacement Family
rplcFamSymbol = actvDoc.GetElement(rplcFam.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
rplcFamSymbol.Activate();
#endregion
#region Loop Thru all family instances to be changed based on their "Angle 1" parameter and replace when found.
foreach (Autodesk.Revit.DB.FamilyInstance famInst in allFamInst)
{
try
{
using (Transaction rplcFamInst_trx = new Transaction(actvDoc, "Replace Family Instance"))
{
rplcFamInst_trx.Start();
// Check if current Family instance has the desired family name
if (selectString == famInst.Symbol.FamilyName)
{
// Check if current Family Instance has the desired parameter "Angle 1" with the desired value 45.
foreach (Parameter param in famInst.Parameters)
{
if (param_name == param.Definition.Name)
if (param.AsValueString().Contains("45"))
{
/////// This is where the Replacement Should Happen... ////////
Element e = actvDoc.GetElement(famInst.Id);
//e.ChangeTypeId(rplcFamSymbol.Id);
famInst.Symbol = rplcFamSymbol;
//famInst.Symbol.Activate();
}
}
}
rplcFamInst_trx.Commit();
}//end transaction rplcFamInst_trx
}//end try
catch (System.Exception e)
{
Autodesk.Revit.UI.TaskDialog.Show("rplcFamilyInstances_CN", "I am in rplcFamilies_CN.execte. Exception: " + e.ToString());
}// end catch
} // Foreach Family to edit
#endregion
}// end of Execute