Hi all,
I am trying to collect all generic families in a project and tyring to activate a family with name “Room”.But I am getting an error which says

Here is the code I have used.Can anyone help me to resolve the issue.Code is working when I Place the aforesaid family in the model.I think filtered element collector is collecting the generic family only when it is placed in the model.
public void ActiavteFamilySymbol()
{
Document doc = this.Document;
IList Generic_Famlies = new List();
FamilySymbol RoomTag_Family = null;
//Collecgting Generic Families
Generic_Famlies = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsNotElementType().ToElements();
foreach( var fam in Generic_Famlies)
{
if (fam.Name.Contains("Room"))
{
var RoomTag_Family_Temp = doc.GetElement(fam.GetTypeId());
RoomTag_Family = RoomTag_Family_Temp as FamilySymbol;
}
}
TaskDialog.Show("aCTIVE STATUS",RoomTag_Family.IsActive.ToString());
using (Transaction AF = new Transaction(doc))
{
AF.Start("Start");
if (!RoomTag_Family.IsActive)
{
RoomTag_Family.Activate();
doc.Regenerate();
}
AF.Commit();
}
}