Today I found a quite interesting class searching the API: FamilyInstanceCreationData By passing parameters, you can use doc.Create.NewFamilyInstances2() to generate all components at once. This class can be used for modeling or adjusting components. The method comes with two methods. .axis && .RotateAngle can save the steps of using ElementTransformUtils.RotateElement() after generating components before. It is more concise at call level than generating one by one before. The time difference has not been tested yet. Below is the example in official documentation.
//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); } }