CAD二次开发--根据内部点识别最近外部边界范围即boundary命令代码实现(含源码)

        在AutoCAD中我们知道使用Boundary(BO)命令可以快速找到内部点附近的最近边界范围(通常要求闭合)。然而网上很多文章却停留在如何用BO命令,并没有讲如何用代码去实现!本文将实现代码贴出来并进行简单介绍。 先看下实现效果图吧!

        该功能在某些时候还是具备一定的实际意义的,比如在道路改扩建时,通常需要确定红线范围内的房屋数量,该命令就可以通过房屋的中点坐标快速确定房屋的外轮廓,从而计算占地面积。如果用代码实现,那效率的提升可以说是翻倍的!

目录

1.函数说明

2.源代码

3.测试效果

 4.目前发现问题


1.函数说明

        为了实现根据指定点确定最近范围,需要用到CAD的API 功能Editor.TraceBoundary() 函数。该函数在Editor类下:

 public unsafe DBObjectCollection TraceBoundary(Point3d seedPoint, [MarshalAs(UnmanagedType.U1)] bool detectIslands)
        {
            //IL_001d: Expected I, but got I8
            DBObjectCollection dBObjectCollection =
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
NX二次开发中获取边界类型可以使用以下代码: ``` #include <NXOpen/Part.hxx> #include <NXOpen/Body.hxx> #include <NXOpen/BodyCollection.hxx> #include <NXOpen/Edge.hxx> #include <NXOpen/EdgeCollection.hxx> #include <NXOpen/Features_Feature.hxx> #include <NXOpen/Features_FeatureCollection.hxx> #include <NXOpen/Features_FeatureType.hxx> #include <NXOpen/TopologicalRegion.hxx> #include <NXOpen/TopologicalRegionCollection.hxx> #include <NXOpen/TopologyQuery.hxx> using namespace NXOpen; void GetBoundaryType() { Part *part = NXOpen::Session::GetSession()->Parts()->Work(); BodyCollection *bodies = part->Bodies(); Features::FeatureCollection *features = part->Features(); // Loop through all the bodies in the part for (int i = 0; i < bodies->Count(); i++) { Body *body = bodies->GetItem(i); // Loop through all the edges in the body EdgeCollection *edges = body->GetEdges(); for (int j = 0; j < edges->Count(); j++) { Edge *edge = edges->GetItem(j); // Check if the edge is a boundary edge TopologicalRegionCollection *regions = edge->GetTopology()->GetRegions(); if (regions->Count() == 1) { TopologicalRegion *region = regions->GetItem(0); if (region->IsSolidRegion()) { // The edge is a boundary edge of a solid body // Do something } else if (region->IsSheetRegion()) { // The edge is a boundary edge of a sheet body // Do something } else if (region->IsWireframeRegion()) { // The edge is a boundary edge of a wireframe body // Do something } } } // Loop through all the features in the body for (int j = 0; j < features->Count(); j++) { Features::Feature *feature = features->GetItem(j); // Check if the feature is a boundary feature if (feature->Type() == Features::FeatureType::Boundary) { // The feature is a boundary feature // Do something } } } } ``` 这段代码会遍历当前工作部件中所有的边界,然后通过`GetTopology()`方法获取边界的拓扑结构信息,再通过`GetRegions()`方法获取边界的区域信息,最后根据区域的类型确定边界的类型。另外,还可以通过遍历部件中的所有特征,判断特征类型是否为边界,来获取所有的边界类型。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

韦_恩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值