Disclaimer: This article from the dark knight の creation, please indicate the source, the exchange qq1056291511 https://blog.csdn.net/birdfly2015/article/details/90299545
Scratch. Background
Small partners in the revit secondary development, you may need to get all family types in a family environment, then its wave operation
II. Ideas
1. Open the family file. See Note 1
2. Group Manager FamilyManager, referring to note 2
3. Group obtain this family all types FamilyTypeSet, Note 3 reference
4. The operation of all types of aromatic or aliphatic type of a method, see Notes 4,5
5. save, close the document family, see Notes 6 and 7
III. Code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
namespace heiyedeqishi
{
[Transaction(TransactionMode.Manual)]
class Revit_API_Executable1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document document = uidoc.Document;
//1族文件地址,这样我们就能打开族文档,并且获得这个文档的document
string filePath = @"D:\黑夜的骑士\某个族.rfa";
Document doc = document.Application.OpenDocumentFile(filePath);
//2获得族管理器
FamilyManager familyManager = doc.FamilyManager;
try
{
//因为修改族是对revit内部数据进行修改,所以需要开启事物
Transaction trans = new Transaction(doc, "修改族类型");
trans.Start();
//3得到当前所有的族类型集合
FamilyTypeSet familyTypeSet = doc.FamilyManager.Types;
//4需要对所有族类型进行操作的话
foreach (FamilyType familyType in familyTypeSet)
{
//设置当前操作对象为此族类型
familyManager.CurrentType = familyType;
//小伙伴们的精彩操作
//...
}
//5从所有族类型中获取某个族类型,假设名字为"墙1"
string singleFamilySymbolName = "墙1";
foreach (FamilyType familyType in familyTypeSet)
{
if (familyType.Name == "墙1")
{
//将此族类型设置为当前的操作对象
doc.FamilyManager.CurrentType = familyType;
//小伙伴们的精彩操作
//...
}
}
//事物结束
trans.Commit();
//6对文档进行保存
doc.Save();
//7关闭打开的这个文档
doc.Close();
return Result.Succeeded;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
}
}
}
IV Notes
In the project environment, or template environment, we are family related operations can be carried out by FamilySymbol, but in a family environment, will be very convenient to use FamilyType