当前位置:网站首页>Revit secondary development - project file to family file

Revit secondary development - project file to family file

2022-07-07 22:22:00 Hey, hey, hey, hey, hey

Project file (.rvt) Convert to family file (.rfa), The system family in the project cannot be transferred in this way

1. Get the instance in the project

2.  Traverse instance record properties / coordinate / Centerline, etc , And save the instance as .rfa Format file

3. Load an empty family file , And load all the just exported instances into the empty family file to set their properties / Coordinates, etc

4. Save the family file

// Get instance 
FilteredElementCollector fec = new FilteredElementCollector(doc).ofClass(typeof(FamilyInstance));

fec.UnionWith(new FilteredElementCollector(doc).ofClass(typeof(HostObject))).ToElements();

// Property record ...
Dictionary<string,ParamaterSet> dicPara = new Dictionary<string,ParamaterSet>();
// export path 
List<string> lstExportPath = new List<string>();

// Save the instance .rfa file 
if(elem is FamilyInstance)
{
    Familyinstance ins = elem as Familyinstance;
    Family family = ins.Symbol.Family;
    Document insDoc = ins.EditFamily(family);
    string sPath = "d:\\"+ins.Id+".rfa";
    lstExportPath.Add(sPath);
    insDoc.SaveAs("d:\\ins.rfa");
    insDoc.Close(false);
    dicPara.Add(sPath,ins.Paramters);
}

// Load an empty family and load the instance   establish 
Family fa = null;
using(Transaction trans = new Transaction(doc,"load"))
{
    trans.start();
    try
    {
        doc.LoadFamily("",familyLoadOption,out fa);
        trans.Commit();
    }
    catch
    {
        trans.RollBack();
    }
}

// Traverse lstExportPath  establish 
Document fDoc = doc.EditFamily(fa);
foreach(string path in lstExportPath)
{
    Family loadFamily;
    FamilySymbol fs = null;
    fDoc.LoadFamily(path,familyLoadOption,out loadFamily);
    ISet<ElementId> symbolIds = loadFamily.GetFamilySymbolIds();
    foreach(Elementid symbolId in symbolIds)
    {
        fs = fDoc.GetElement(symbolId) as FamilySymbol;
        if(fs == null) Continue;
        if(!fs.IsActive) { fs.Activate(); break; }
    }
    if(fs == null) Comtinue;
    // Here we create point based instances ,  Line / Noodles   Anyway, this method 
    fDoc.FamilyCreate.NewFamilyInstance( Recorded coordinates ,fs,StructuralType.NoStructural);
    // Set properties , Rotation Angle  Math.PI / 180 *  Recorded angle 
    ...
    ...
    ...
}
// Just save it after you create it 
fDoc.SaveAs(" route ");
fDoc.Close(false);

It's tiring to beat your heart with your hands , Function is not difficult , I wrote a general .

I hope that helps .

 

------------------------------------------------------------------------------------------ Update -----------------------------------------------------------------------------------------------------------------------------

Forget to consider the built-in model , Just in     Save the instance in the project as rfa When you file     Add a judgment

if(!family.IsEditable) continue;

 

原网站

版权声明
本文为[Hey, hey, hey, hey, hey]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130606207444.html