今天检索API发现一个比较有意思的类:FamilyInstanceCreationData
通过传入参数可以使用doc.Create.NewFamilyInstances2()一次生成所有构件。
这个类可以用于翻模或调整构件的情况。在方法中自带两种方法.axis&&.RotateAngle可以省却
我之前生成构建后ElementTransformUtils.RotateElement()使用的步骤,比以前挨个生成在代码层面要简洁一些,目前还未测试出时间差别。下面是官方里面的示例。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
ICollection<ElementId> BatchCreateColumns(Autodesk.Revit.DB.Document document, Level level)
{
List<FamilyInstanceCreationData> fiCreationDatas = new List<FamilyInstanceCreationData>();

//ElementSet elementSet = null;
ICollection<ElementId> elementSet = null;

//Try to get a FamilySymbol
FamilySymbol familySymbol = null;
FilteredElementCollector collector = new FilteredElementCollector(document);
ICollection<Element> collection = collector.OfClass(typeof(FamilySymbol)).ToElements();
foreach (Element e in collection)
{
familySymbol = e as FamilySymbol;
if (null != familySymbol.Category)
{
if ("Structural Columns" == familySymbol.Category.Name)
{
break;
}
}
}

if (null != familySymbol)
{
//Create 10 FamilyInstanceCreationData items for batch creation
for (int i = 1; i < 11; i++)
{
XYZ location = new XYZ(i * 10, 100, 0);
FamilyInstanceCreationData fiCreationData =
new FamilyInstanceCreationData(location, familySymbol, level, StructuralType.Column);

if (null != fiCreationData)
{
fiCreationDatas.Add(fiCreationData);
}
}

if (fiCreationDatas.Count > 0)
{
// Create Columns
elementSet = document.Create.NewFamilyInstances2(fiCreationDatas);
}
else
{
throw new Exception("Batch creation failed.");
}
}
else
{
throw new Exception("No column types found.");
}

return elementSet;
}