Revit API批量布置函数doc.Create.NewFamilyInstances();
start
url:http://greatverve.cnblogs.com/p/revit-api-NewFamilyInstances.html
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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。