首页 > Windows开发 > 详细

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

时间:2014-03-06 22:34:15      阅读:812      评论:0      收藏:0      [点我收藏+]
start
using ACreat = Autodesk.Revit.Creation;
bubuko.com,布布扣
//批量布置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;
    }
}
bubuko.com,布布扣
url:http://greatverve.cnblogs.com/p/revit-api-NewFamilyInstances.html

Revit API批量布置函数doc.Create.NewFamilyInstances();,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/greatverve/p/revit-api-NewFamilyInstances.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!