轴网
轴网轴网
轴网由Element类派生的Grid类来表示。它包含所有的轴网属性和方法。继承的Name
属性用于检索轴网线的编号圈内容。
1.曲线(Curve )
Grid类Curve属性获取-一个对象, 该对象代表轴线几何形状。
●如果IsCurved属性返回true, 则Curve属性为Arc类对象。
●如果IsCurved属性返回false, 则Curve属性为Line类对象。
轴网对应的类是Grid,也继承自Element
1)轴网曲线(Curve)
通过Grid.Curve属性能够拿到轴网的曲线,如果Grid.IsCurved返回true,那么Curve将是一个弧形曲线Arc 对象,否则就是Line对象。
2)创建轴网
创建轴网的函数有两个重载,分别对应于直线和弧线轴网:
●Document. Create. NewGrid( Arcarc)
●Document. Create. NewGrid(Lineline)
2.创建轴网( Creating a Grid)
在Revit平台API中,有两个重载Document方法可用于创建新的轴网。采用不同的参
数使用代码3-39方法,可以创建曲线或直线轴网。
代码3- -39: NewGrid( )
public Grid NewGrid (Arc arc);
public Grid NewGrid (Line line );
注意:用于创建轴网的弧线或直线必须在水平面内。
注意:在Revit中,轴网创建时会以数字或字母顺序自动命名。
多个轴网可以使用Document.NewGrids( )方法同时进行创建,该方法采用CurveArray
参数。
using System;using Autodesk.Revit.DB;using Autodesk.Revit.UI;namespace ElementBasicDemo{[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]public class CreateGridCmd : IExternalCommand{public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements){try{Document doc = commandData.Application.ActiveUIDocument.Document;// 弧线double arcRadius = 20000/304.8 ; // 弧线的内径长:英寸, 1 英寸 = 304.8mmdouble startAngle = 0;double endAngle = Math.PI / 4.0;Arc arc = Arc.Create(XYZ.Zero,arcRadius,startAngle,endAngle,XYZ.BasisX,XYZ.BasisY);// 直线XYZ startPoint = XYZ.BasisY * arcRadius;XYZ endPoint = XYZ.BasisX * arcRadius + startPoint;Line line = Line.CreateBound(startPoint, endPoint);using (Transaction transaction = new Transaction(doc)){if (transaction.Start("轴网") == TransactionStatus.Started){try{Grid arcGrid = CreateArcGrid(doc, arc, "弧形轴网");Grid lineGrid = CreateLineGrid(doc, line, "线性轴网");GridType gdtype = (GridType) doc.GetElement(lineGrid.GetTypeId());SetGridType(gdtype);if (mitted != mit()){TaskDialog.Show("失败", "轴网创建失败");}}catch (Exception exception){transaction.RollBack();throw exception;}}}return Autodesk.Revit.UI.Result.Succeeded;}catch (Exception ex){message = ex.Message;return Autodesk.Revit.UI.Result.Failed;}}private Grid CreateArcGrid(Document doc, Arc arc, string gridname){Grid arcGrid = Grid.Create(doc, arc);arcGrid.Name = gridname;return arcGrid;}private Grid CreateLineGrid(Document doc, Line line, string gridname){Grid lineGrid = Grid.Create(doc, line);lineGrid.Name = gridname;return lineGrid;}private GridType SetGridType(GridType gridType){if (null != gridType){gridType.get_Parameter(BuiltInParameter.GRID_CENTER_SEGMENT_STYLE).SetValueString("连续");}return gridType;}}}
using (Transaction transaction = new Transaction(RevitDoc)){transaction.Start("Create Grid");Grid grid = RevitDoc.Create.NewGrid(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(10, 10, 0)));grid.Name = "BB";mit();}