乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: OmarSuliman

[编程交流] 获取块参照内的多行文字

[复制链接]

1

主题

11

帖子

10

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:54:29 | 显示全部楼层
第二个是找出点是在区域对象的内侧还是外侧,我也试过了。
 
  1. Namespace BRepSamples
  2.    Public NotInheritable Class Containment
  3.        Private Sub New()
  4.        End Sub
  5.        '' <summary>
  6.        ''
  7.        '' This sample shows how to use the BREP API to do
  8.        '' simple topographical point/boundary classification
  9.        '' on regions.
  10.        ''
  11.        '' This code requires a reference to AcDbMgdBrep.dll
  12.        ''
  13.        '' The sample prompts for a region object; gets a BRep
  14.        '' object representing the region; and then repeatedly
  15.        '' prompts for points, and computes and displays the
  16.        '' containment (inside, outside, or on an edge) of each
  17.        '' selected point.
  18.        ''
  19.        '' A point within an inner loop is considered to be
  20.        '' 'ouside' the region's area, and so if you perform
  21.        '' this operation on a complex region with inner loops,
  22.        '' points contained within an inner loop will yield a
  23.        '' result of PointContainment.Outside.
  24.        '
  25.        '' This is the most robust means of determining if a
  26.        '' point lies within the implied boundary formed by a
  27.        '' collection of AutoCAD entites that can be used to
  28.        '' create a valid AutoCAD Region object, and is the
  29.        '' preferred means of doing simple point containment
  30.        '' testing.
  31.        ''
  32.        '' You can adapt this code to perform containment tests
  33.        '' on various AutoCAD entities such as closed polylines,
  34.        '' splines, ellipses, etc., by generating a region from
  35.        '' the closed geometry, using it to do the containment
  36.        '' test, and then disposing it without having to add it
  37.        '' to a database.
  38.        ''
  39.        '' Note that the sample code was designed to work with
  40.        '' regions that lie in the WCS XY plane and points that
  41.        '' lie in the same plane.
  42.        ''
  43.        '' </summary>
  44.        <CommandMethod("CONTAINMENT")> _
  45.        Public Shared Sub ContainmentCommand()
  46.            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  47.            Dim id As ObjectId = GetRegion(ed, vbLf & "Select a region: ")
  48.            If Not id.IsNull Then
  49.                Using tr As Transaction = ed.Document.TransactionManager.StartTransaction()
  50.                    Try
  51.                        Dim region As Region = TryCast(id.GetObject(OpenMode.ForRead), Region)
  52.                        Dim ppo As New PromptPointOptions(vbLf & "Select a point: ")
  53.                        ppo.AllowNone = True
  54.                        While True
  55.                            ' loop while user continues to pick points
  56.                            '' Get a point from user:
  57.                            Dim ppr As PromptPointResult = ed.GetPoint(ppo)
  58.                            If ppr.Status <> PromptStatus.OK Then
  59.                                ' no point was selected, exit
  60.                                Exit While
  61.                            End If
  62.                            ' use the GetPointContainment helper method below to
  63.                            ' get the PointContainment of the selected point:
  64.                            Dim containment As PointContainment = GetPointContainment(region, ppr.Value)
  65.                            ' Display the result:
  66.                            ed.WriteMessage(containment.ToString())
  67.                        End While
  68.                    Finally
  69.                        tr.Commit()
  70.                    End Try
  71.                End Using
  72.            End If
  73.        End Sub
  74.        '' <summary>
  75.        ''
  76.        '' This variation performs point contianment testing
  77.        '' against any closed curve from which a simple region
  78.        ' (e.g., no inner-loops) can be genreated, using the
  79.        '' Region.CreateFromCurves() API.
  80.        ''
  81.        '' </summary>
  82.        <CommandMethod("CURVECONTAINMENT")> _
  83.        Public Shared Sub CurveContainmentCommand()
  84.            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  85.            Dim id As ObjectId = GetCurve(ed, vbLf & "Select a closed Curve: ")
  86.            If Not id.IsNull Then
  87.                Using tr As Transaction = ed.Document.TransactionManager.StartTransaction()
  88.                    Try
  89.                        Dim curve As Curve = DirectCast(id.GetObject(OpenMode.ForRead), Curve)
  90.                        If Not curve.Closed Then
  91.                            ed.WriteMessage(vbLf & "Invalid selection, requires a CLOSED curve")
  92.                            Return
  93.                        End If
  94.                        Using region As Region = RegionFromClosedCurve(curve)
  95.                            Dim ppo As New PromptPointOptions(vbLf & "Select a point: ")
  96.                            ppo.AllowNone = True
  97.                            While True
  98.                                ' loop while user continues to pick points
  99.                                '' Get a point from user:
  100.                                Dim ppr As PromptPointResult = ed.GetPoint(ppo)
  101.                                If ppr.Status <> PromptStatus.OK Then
  102.                                    ' no point was selected, exit
  103.                                    Exit While
  104.                                End If
  105.                                ' use the GetPointContainment helper method below to
  106.                                ' get the PointContainment of the selected point:
  107.                                Dim containment As PointContainment = GetPointContainment(region, ppr.Value)
  108.                                ' Display the result:
  109.                                ed.WriteMessage(containment.ToString())
  110.                            End While
  111.                        End Using
  112.                    Finally
  113.                        tr.Commit()
  114.                    End Try
  115.                End Using
  116.            End If
  117.        End Sub
  118.        ' this helper method takes a Region and a Point3d that must be
  119.        ' in the plane of the region, and returns the PointContainment
  120.        ' of the given point, adjusted to correctly indicate its actual
  121.        ' relationship to the region (inside/on boundary edge/outside).
  122.        Public Shared Function GetPointContainment(region As Region, point As Point3d) As PointContainment
  123.            Dim result As PointContainment = PointContainment.Outside
  124.            '' Get a Brep object representing the region:
  125.            Using brep As New Brep(region)
  126.                If brep IsNot Nothing Then
  127.                    ' Get the PointContainment and the BrepEntity at the given point:
  128.                    Using ent As BrepEntity = brep.GetPointContainment(point, result)
  129.                        ' GetPointContainment() returns PointContainment.OnBoundary
  130.                        ' when the picked point is either inside the region's area
  131.                        '' or exactly on an edge.
  132.                        '
  133.                        '' So, to distinguish between a point on an edge and a point
  134.                        '' inside the region, we must check the type of the returned
  135.                        '' BrepEntity:
  136.                        ''
  137.                        '' If the picked point was on an edge, the returned BrepEntity
  138.                        '' will be an Edge object. If the point was inside the boundary,
  139.                        '' the returned BrepEntity will be a Face object.
  140.                        '' So if the returned BrepEntity's type is a Face, we return
  141.                        '' PointContainment.Inside:
  142.                        If TypeOf ent Is Autodesk.AutoCAD.BoundaryRepresentation.Face Then
  143.                            result = PointContainment.Inside
  144.                        End If
  145.                    End Using
  146.                End If
  147.            End Using
  148.            Return result
  149.        End Function
  150.        Public Shared Function RegionFromClosedCurve(curve As Curve) As Region
  151.            If Not curve.Closed Then
  152.                Throw New ArgumentException("Curve must be closed.")
  153.            End If
  154.            Dim curves As New DBObjectCollection()
  155.            curves.Add(curve)
  156.            Using regions As DBObjectCollection = Region.CreateFromCurves(curves)
  157.                If regions Is Nothing OrElse regions.Count = 0 Then
  158.                    Throw New InvalidOperationException("Failed to create regions")
  159.                End If
  160.                If regions.Count > 1 Then
  161.                    Throw New InvalidOperationException("Multiple regions created")
  162.                End If
  163.                Return regions.Cast(Of Region)().First()
  164.            End Using
  165.        End Function
  166.        Public Shared Function GetPointContainment(curve As Curve, point As Point3d) As PointContainment
  167.            If Not curve.Closed Then
  168.                Throw New ArgumentException("Curve must be closed.")
  169.            End If
  170.            Dim region As Region = RegionFromClosedCurve(curve)
  171.            If region Is Nothing Then
  172.                Throw New InvalidOperationException("Failed to create region")
  173.            End If
  174.            Using region
  175.                Return GetPointContainment(region, point)
  176.            End Using
  177.        End Function
  178.        Public Shared Function GetCurve(editor As Editor, msg As String) As ObjectId
  179.            Dim peo As New PromptEntityOptions(msg)
  180.            peo.SetRejectMessage("Invalid selection: requires a closed Curve,")
  181.            peo.AddAllowedClass(GetType(Curve), False)
  182.            Dim res As PromptEntityResult = editor.GetEntity(peo)
  183.            Return If(res.Status = PromptStatus.OK, res.ObjectId, ObjectId.Null)
  184.        End Function
  185.        Public Shared Function GetRegion(editor As Editor, msg As String) As ObjectId
  186.            Dim peo As New PromptEntityOptions(msg)
  187.            peo.SetRejectMessage("Invalid selection: requires a region,")
  188.            peo.AddAllowedClass(GetType(Region), False)
  189.            Dim res As PromptEntityResult = editor.GetEntity(peo)
  190.            Return If(res.Status = PromptStatus.OK, res.ObjectId, ObjectId.Null)
  191.        End Function
  192.    End Class
  193. End Namespace
回复

使用道具 举报

18

主题

434

帖子

422

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
94
发表于 2022-7-6 22:56:44 | 显示全部楼层
它不会像你期望的那样工作。。。它还搜索块定义内的多行文字。
回复

使用道具 举报

1

主题

11

帖子

10

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:59:37 | 显示全部楼层
 
没问题,会解决的。
谢谢你抽出时间。
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 23:04:32 | 显示全部楼层
我仍然认为您需要发布一个DWG文件来说明实体,因为您希望您的例程能够找到它们。理想情况下,示例文件将演示应该通过测试的设置,以及不应该通过测试的设置。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 09:00 , Processed in 0.480583 second(s), 58 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表