多谢lzh741206的关注。
还是采用-Boundary命令的方式来实现的,不过没有我在上面说的那么土,要用新图层什么的,哈哈
参考了“ObjectARX编程站”如下帖子(感谢zmkm1234和wz0406):
http://www.objectarx.net/forum.php?mod=viewthread&tid=867&highlight=%B1%DF%BD%E7
我的VB.Net代码如下:
Public Class ModelSpace
<Runtime.InteropServices.DllImport("acad.exe", SetLastError:=True)> _
Private Shared Function acedCmd(ByVal vlist As System.IntPtr) As Integer
End Function
Public Shared Function GetColsedBoundary(ByVal InnerX As Double, ByVal InnerY As Double) As ObjectId
Dim rb As ResultBuffer = New ResultBuffer
Try
rb.Add(New TypedValue(5005, "._-BOUNDARY"))
rb.Add(New TypedValue(5005, "_AD"))
rb.Add(New TypedValue(5005, "_IS"))
If IslandDetection = 1 Then
rb.Add(New TypedValue(5005, "_Y")) 'Y表示启动孤单检测
Else
rb.Add(New TypedValue(5005, "_N")) 'N表示不启动孤单检测
rb.Add(New TypedValue(5005, "_N")) '射线投影类型:默认的Nearest<N>。
'注意:有时会出现点在边界外的问题,所以尽量要启用孤岛检测
End If
rb.Add(New TypedValue(5005, "_OB"))
rb.Add(New TypedValue(5005, "PO"))
rb.Add(New TypedValue(5005, ""))
rb.Add(New TypedValue(5005, (InnerX.ToString + ("," + InnerY.ToString))))
rb.Add(New TypedValue(5005, ""))
acedCmd(rb.UnmanagedObject)
Dim db As Database = GetDB()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim psr As PromptSelectionResult = ed.SelectLast
Dim ObjIds As ObjectId() = psr.Value.GetObjectIds
If ObjIds IsNot Nothing And ObjIds.Length > 0 Then
Dim ObjId As ObjectId = ObjIds(0)
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim obj As DBObject = trans.GetObject(ObjId, OpenMode.ForRead)
If TypeOf (obj) Is Polyline Then
Dim ObjectPolyPolyline As Polyline = obj
Dim msg As String = String.Format("Area = {0} ", ObjectPolyPolyline.Area)
ed.WriteMessage(msg)
Return ObjId
End If
End Using
End If
Catch ex As System.Exception
MsgBox("Hatch Boundary Error " & ex.Message)
Return ObjectId.Null
Finally
rb.Dispose()
End Try
End Function
End Class |