using ACreat = Autodesk.Revit.Creation;
//批量布置doc.Create.NewFamilyInstances();
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmd : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
UIApplication uiApp = cmdData.Application;
Document doc = uiDoc.Document;
Selection sel = uiDoc.Selection;
Transaction ts = new Transaction(doc, "http://revit.5d6d.com");
try
{
ts.Start();
//找一个管件
FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
IList<Element> collection = collector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_DuctFitting).ToElements();
FamilySymbol familySymbol = collection[0] as FamilySymbol;
//区域布置
PickedBox pb = sel.PickBox(PickBoxStyle.Directional, "请选择区域");
List<XYZ> listXYZ = new List<XYZ>();//判断一些布置点
double dDistance = 3;//间距
XYZ xyzStart = pb.Min;//Max右下点Min左上点,暂时这样理解。
bool bWhile = true;
while (bWhile)
{
xyzStart += new XYZ(dDistance, -dDistance, 0);
if (xyzStart.X > pb.Max.X || xyzStart.Y < pb.Max.Y)
bWhile = false;
else
listXYZ.Add(xyzStart);
}
//批量布置
List<ACreat.FamilyInstanceCreationData> fiCreationDatas = new List<ACreat.FamilyInstanceCreationData>();
foreach (XYZ item in listXYZ)
{
ACreat.FamilyInstanceCreationData fiCreationData =
new ACreat.FamilyInstanceCreationData(item, familySymbol, familySymbol.Level, StructuralType.NonStructural);
if (null != fiCreationData)
{
fiCreationDatas.Add(fiCreationData);
}
}
doc.Create.NewFamilyInstances(fiCreationDatas);
ts.Commit();
}
catch (Exception ex)
{
ts.RollBack();
}
return Result.Succeeded;
}
}
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmd : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
UIApplication uiApp = cmdData.Application;
Document doc = uiDoc.Document;
Selection sel = uiDoc.Selection;
Transaction ts = new Transaction(doc, "http://revit.5d6d.com");
try
{
ts.Start();
//找一个管件
FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
IList<Element> collection = collector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_DuctFitting).ToElements();
FamilySymbol familySymbol = collection[0] as FamilySymbol;
//区域布置
PickedBox pb = sel.PickBox(PickBoxStyle.Directional, "请选择区域");
List<XYZ> listXYZ = new List<XYZ>();//判断一些布置点
double dDistance = 3;//间距
XYZ xyzStart = pb.Min;//Max右下点Min左上点,暂时这样理解。
bool bWhile = true;
while (bWhile)
{
xyzStart += new XYZ(dDistance, -dDistance, 0);
if (xyzStart.X > pb.Max.X || xyzStart.Y < pb.Max.Y)
bWhile = false;
else
listXYZ.Add(xyzStart);
}
//批量布置
List<ACreat.FamilyInstanceCreationData> fiCreationDatas = new List<ACreat.FamilyInstanceCreationData>();
foreach (XYZ item in listXYZ)
{
ACreat.FamilyInstanceCreationData fiCreationData =
new ACreat.FamilyInstanceCreationData(item, familySymbol, familySymbol.Level, StructuralType.NonStructural);
if (null != fiCreationData)
{
fiCreationDatas.Add(fiCreationData);
}
}
doc.Create.NewFamilyInstances(fiCreationDatas);
ts.Commit();
}
catch (Exception ex)
{
ts.RollBack();
}
return Result.Succeeded;
}
}
Revit API批量布置函数doc.Create.NewFamilyInstances();,布布扣,bubuko.com