IntersectWith

 <CommandMethod("inters", CommandFlags.UsePickSet)> _
    Public Sub GetInters()
        Dim doc As Document = acadApp.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim tr As Transaction = db.TransactionManager.StartTransaction
        Try
            Using (tr)
                Dim opt As New PromptEntityOptions(vbLf & "Select line: ")
                opt.SetRejectMessage(vbLf & "Select line only")
                opt.AllowNone = False
                opt.AllowObjectOnLockedLayer = True
                opt.AddAllowedClass(GetType(Line), True)
                Dim res As PromptEntityResult = ed.GetEntity(opt)
                If res.Status <> PromptStatus.OK Then Return
                Dim lid As ObjectId = res.ObjectId
                opt.AddAllowedClass(GetType(Polyline), True)
                opt.SetRejectMessage(vbLf & "Select polyline only")
                opt.Message = vbLf & "Select polyline: "
                res = ed.GetEntity(opt)
                If res.Status <> PromptStatus.OK Then Return
                Dim pid As ObjectId = res.ObjectId
                Dim pts As Point3dCollection = New Point3dCollection()
                ed.WriteMessage(vbLf & "{0} <> {1};", lid, pid)
                Dim enl As Line = CType(tr.GetObject(lid, OpenMode.ForRead), Line)
                Dim enp As Polyline = CType(tr.GetObject(pid, OpenMode.ForRead), Polyline)
                Dim plane As Plane = New Plane(ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Origin, ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis)
                enl.IntersectWith(enp, Intersect.OnBothOperands, plane, pts, 0, 0)
                ed.WriteMessage(vbLf & "Number of intersections: {0}", pts.Count)
                Dim i As Integer = 1
                For Each pt As Point3d In pts
                    ed.WriteMessage(vbLf & "Point number {0}: ({1}, {2}, {3})", i, pt.X, pt.Y, pt.Z)
                    i += 1
                Next
                tr.Commit()
            End Using
        Catch ex As Autodesk.AutoCAD.Runtime.Exception
            ed.WriteMessage(vbLf & "{0}", ex.Message)
        End Try
    End Sub


Entity entityPointer:与该实体相交的另一个实体

Intersect intersectType:相交的类型,为一枚举

Point3dCollection points:获取所有相交的交点

Int32 thisGraphicSystemMarker:使用该方法实体的下级实体(subentity)的图形系统标记,如果不适用就用缺省值0。

Int32 otherGraphicSystemMarker:其他的下级实体的图形系统标记,如果不适用就用缺省值0。

关于Intersect枚举的成员

成员名

描述

ExtendBoth

两个实体都延伸

ExtendArgument

只延伸作为参数的实体(该方法的第一个参数)

ExtendThis

只延伸原实体(调用该方法的实体)

OnBothOperands

两个实体都不延伸





Please follow WeChat's public account ByCAD