嗨SEANT
谢谢你的帮助
我正在编写两段不同的代码
第一个是找到多边形内的点,它工作正常,我试图转换代码以达到我的需要,但我直到现在都失败了
- <CommandMethod("TEST")> _
- Public Sub Test()
- Dim doc As Document = Application.DocumentManager.MdiActiveDocument
- Dim db As Database = doc.Database
- Dim ed As Editor = doc.Editor
- Dim peo As New PromptEntityOptions(vbLf & "Select a polyline: ")
- peo.SetRejectMessage("Only a polyline !")
- peo.AddAllowedClass(GetType(Polyline), True)
- Dim per As PromptEntityResult = ed.GetEntity(peo)
- If per.Status <> PromptStatus.OK Then
- Return
- End If
- Using tr As Transaction = db.TransactionManager.StartOpenCloseTransaction()
- Dim pline As Polyline = DirectCast(tr.GetObject(per.ObjectId, OpenMode.ForRead), Polyline)
- If Not pline.Closed Then
- ed.WriteMessage(vbLf & "Polyline must be closed.")
- Return
- End If
- Dim curves As New DBObjectCollection()
- curves.Add(pline)
- Try
- Using regions As DBObjectCollection = Region.CreateFromCurves(curves)
- Using region__1 As Region = DirectCast(regions(0), Region)
- Dim ppo As New PromptPointOptions(vbLf & "Pick a point <quit>: ")
- ppo.AllowNone = True
- While True
- Dim ppr As PromptPointResult = ed.GetPoint(ppo)
- If ppr.Status <> PromptStatus.OK Then
- Exit While
- End If
- Application.ShowAlertDialog(GetPointContainment(region__1, ppr.Value).ToString())
- End While
- End Using
- End Using
- Catch exn As System.Exception
- ed.WriteMessage(vbLf & "Error: " & exn.Message)
- End Try
- End Using
- End Sub
- Private Function GetPointContainment(region As Region, point As Point3d) As PointContainment
- Dim result As PointContainment = PointContainment.Outside
- Using brep As New Brep(region)
- If brep IsNot Nothing Then
- Using ent As BrepEntity = brep.GetPointContainment(point, result)
- If TypeOf ent Is Autodesk.AutoCAD.BoundaryRepresentation.Face Then
- result = PointContainment.Inside
- End If
- End Using
- End If
- End Using
- Return result
- End Function
|