Revit二次开发之拾取轴网交点和标高
参考:
https://blog.csdn.net/imfour/article/details/80148470
http://greatverve.cnblogs.com/archive/2011/03/16/revit-Intersection.html
需要找到到布设脚手架起点,所以最终决定利用轴网来实现此功能
1 public static XYZ Grid(UIDocument uiDocument) 2 { 3 Document document = uiDocument.Document; 4 5 //选择点 6 MessageBox.Show("选择轴网交点(大概就可以会自动识别)"); 7 XYZ sel_point = uiDocument.Selection.PickPoint(ObjectSnapTypes.None,"选择轴网交点"); 8 9 //获取所有轴网 10 FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document); 11 filteredElementCollector.OfClass(typeof(Grid)); 12 13 //过滤出所有直线轴网 14 List<Grid> lineGrid = new List<Grid>(); 15 foreach (Grid g in filteredElementCollector) 16 { 17 if ((g.Curve as Line) != null) lineGrid.Add(g); 18 } 19 //变量; 20 Grid grid_n1 = null; 21 Grid grid_n2 = null; 22 double dis1 = double.MaxValue; 23 double dis2 = double.MaxValue; 24 //遍历轴网,计算出离选择点最近的一条轴网 25 foreach (Grid g in lineGrid) 26 { 27 if (g.Curve.Distance(sel_point) < dis1) 28 { 29 grid_n1 = g; 30 dis1 = g.Curve.Distance(sel_point); 31 } 32 } 33 //遍历轴网,计算出离选择点最近的第二条轴网 34 foreach (Grid g in lineGrid) 35 { 36 if (!(g.Curve as Line).Direction.IsAlmostEqualTo((grid_n1.Curve as Line).Direction) && g.Curve.Distance(sel_point) < dis2) 37 { 38 grid_n2 = g; 39 dis2 = g.Curve.Distance(sel_point); 40 } 41 } 42 43 Line line1 = grid_n1.Curve as Line; 44 Line line2 = grid_n2.Curve as Line; 45 46 IntersectionResultArray results;//交点数组 47 SetComparisonResult result = line1.Intersect(line2, out results); 48 49 if (result != SetComparisonResult.Overlap)//重叠,没有重叠就是平行 50 { 51 throw new InvalidOperationException("重叠,没有重叠就是平行"); 52 } 53 if (results == null || results.Size != 1)//没有交点或者交点不是1个 54 { 55 throw new InvalidOperationException("没有交点或者交点不是1个"); 56 } 57 IntersectionResult iResult = results.get_Item(0);//取得交点 58 XYZ intersectionPoint = iResult.XYZPoint;//取得交点坐标 59 60 return intersectionPoint; 61 }
但随后发现,上述方法得到的Z坐标一直都是0,所以无奈,只能在去寻找标高,来作为Z坐标
但要注意单位,方法返回的数值为英尺,包括坐标系的单位均为英尺,所以如果想化成毫米要*304.8
1 private static double level(UIDocument uiDocument,string LevelName) 2 { 3 Document document = uiDocument.Document; 4 5 Selection selection = uiDocument.Selection; 6 7 Transaction transaction = new Transaction(document, "level"); 8 transaction.Start(); 9 10 FilteredElementCollector collector = new FilteredElementCollector(uiDocument.Document); 11 ICollection<Element> collection = collector.OfClass(typeof(Level)).ToElements(); 12 Level level = null; 13 foreach (Element e in collection) 14 { 15 if (e.Name == LevelName) 16 { 17 level = (Level)e; 18 } 19 } 20 transaction.Commit(); 21 22 double Y = level.ProjectElevation; 23 return Y; 24 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器