Revit二次开发——轴网
轴网
轴网
轴网由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.8mm
double 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 (TransactionStatus.Committed != transaction.Commit())
{
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";
transaction.Commit();
}
本文来自博客园,作者:Patrick-Rex,转载请注明原文链接:https://www.cnblogs.com/patrickrex/p/18028778
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升