创建轴网

创建轴网的函数有两个重载,分别对应于直线和弧线轴网:

  • Document.Create.NewGrid(Lineline)
  • Document.Create.NewGrid(Arcarc)

以下代码为创建直线轴网:

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class class1 : IExternalCommand
    {
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData CommandData, ref string messages, ElementSet elements)
        {
            UIApplication uiApp = CommandData.Application;
            Autodesk.Revit.ApplicationServices.Application app = uiApp.Application;
            Document doc = uiApp.ActiveUIDocument.Document;

            using (Transaction transaction = new Transaction(doc))
            {
                transaction.Start("Creat Grid");
                Grid grid = doc.Create.NewGrid(Line.CreateBound(new XYZ(0,0,0), new XYZ(50,50,0)));
                grid.Name = "BB";
                transaction.Commit();
            }
            using (Transaction transaction = new Transaction(doc))
            {
                transaction.Start("Creat Grid");
                Grid grid1 = doc.Create.NewGrid(Line.CreateBound(new XYZ(-10,10,0), new XYZ(40,60,0)));
                grid1.Name = "CC";
                transaction.Commit();
            }
            return Result.Succeeded;
        }
    }

注意:
1.传入参数对应的直线或弧线所在的平面必须是一个水平的。
2.可以通过Grid.Name属性来设置轴网的名称。如果被设置的名字被占用,会有ArgumentException抛出。

你可能感兴趣的:(轴网)