CAD二次开发判断点是否在一个区域内


CAD二次开发判断点是否在一个区域内 Extents3d.AddPoint Method
    <CommandMethod("cmd2")> _
    Public Shared Sub cmd2()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Using tr As Transaction = db.TransactionManager.StartTransaction()
            Dim blockTbl As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
            Dim modelSpace As BlockTableRecord = TryCast(tr.GetObject(blockTbl(BlockTableRecord.ModelSpace), OpenMode.ForRead), BlockTableRecord)

            Dim polyline As New Polyline()
            polyline.AddVertexAt(polyline.NumberOfVertices, New Autodesk.AutoCAD.Geometry.Point2d(), 0, 0, 0)
            polyline.AddVertexAt(polyline.NumberOfVertices, New Autodesk.AutoCAD.Geometry.Point2d(100, 0), 0, 0, 0)
            polyline.AddVertexAt(polyline.NumberOfVertices, New Autodesk.AutoCAD.Geometry.Point2d(100, 100), 0, 0, 0)
            polyline.AddVertexAt(polyline.NumberOfVertices, New Autodesk.AutoCAD.Geometry.Point2d(0, 100), 0, 0, 0)
            polyline.Closed = True

            Dim polyGeomotr As Object = polyline.GeometricExtents
            Dim polyGeomotrCopy As Object = polyline.GeometricExtents
            Dim polyGeomotrCopy2 As Object = polyline.GeometricExtents
            '外轮廓

            Dim point3D As New Point3d(50, 50, 0)

            polyGeomotrCopy.AddPoint(point3D)
            If polyGeomotrCopy = polyGeomotr Then
                Application.ShowAlertDialog("点在区域内")
            End If
            Dim point3D2 As New Point3d(-50, -50, 0)

            polyGeomotrCopy2.AddPoint(point3D2)
            If polyGeomotrCopy2 = polyGeomotr Then
                Application.ShowAlertDialog("点在区域内")
            Else
                Application.ShowAlertDialog("点在不在区域内")
            End If


            tr.Commit()
        End Using

    End Sub



CAD 世界坐标和用户坐标不一致怎么办?

Copy Objects Between Databases

欢迎关注微信公众账号ByCAD