Place family instance into RVT file

Place family instance into RVT file

Anonymous
Not applicable
461 Views
1 Reply
Message 1 of 2

Place family instance into RVT file

Anonymous
Not applicable

Hi,

I have a problem with placing family instance into rvt project file using Design Automation,

I tested that solution localy with design automation debugger and it worked fine. I recieving nullReference error when I try to get Family symbol by 

var list = new FilteredElementCollector(Document)
               .OfClass(typeof(FamilySymbol));

 

 

0 Likes
462 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

You need to first load your family into Revit.

Then get the symbol and create an instance of family as shown below.

uiApp.ActiveUIDocument.Document.LoadFamily(GlobalVariables.FamilyPath + "Grid_Mass.rfa", out fm);

FamilySymbol MassISymbol = GetSymbol("Grid_Mass", "Grid_Mass");

 

FamilyInstance MassInstance = Doc.Create.NewFamilyInstance(new XYZ(0,0,0), MassISymbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming);

 

public FamilySymbol GetSymbol(string FamilyName, string TypeName)
{
try
{
FilteredElementCollector collector = new FilteredElementCollector(Doc).OfClass(typeof(FamilySymbol));

List<FamilySymbol> symbols = collector.ToElements().Cast<FamilySymbol>().ToList().Where(item => item != null).ToList();

var query = from item in symbols where item.Name == FamilyName  && item.FamilyName == FamilyName select item;

FamilySymbol symbol = query.FirstOrDefault() as FamilySymbol;

if (symbol != null)
{
using (Transaction actrans = new Transaction(Doc, "Activate Symbol"))
{
actrans.Start();

if (symbol.IsActive == false)
symbol.Activate();

actrans.Commit();
return symbol;
}
}
}
catch { }


return null;

}