Revit API批量布置函数doc.Create.NewFamilyInstances();

start
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[0as 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;
    }
}
url:http://greatverve.cnblogs.com/p/revit-api-NewFamilyInstances.html
posted @ 2014-03-06 10:20  大气象  阅读(3312)  评论(0编辑  收藏  举报
http://www.tianqiweiqi.com