Public Class Class1
<CommandMethod("xarea")> _
Public Sub xarea()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim toal As Double = 0
Using trans As Transaction = db.TransactionManager.StartOpenCloseTransaction()
Dim value(0) As TypedValue
value(0) = New TypedValue(DxfCode.Start, "3DSOLID")
Dim fill As SelectionFilter = New SelectionFilter(value)
Dim optsel As New PromptSelectionOptions()
optsel.MessageForAdding = "选择实体:"
Dim selrec As PromptSelectionResult = ed.GetSelection(fill)
If selrec.Status = PromptStatus.OK Then
Dim mysel As SelectionSet = selrec.Value
For Each xobj As SelectedObject In mysel
If Not IsDBNull(xobj) Then
Dim ent As Solid3d = trans.GetObject(xobj.ObjectId, OpenMode.ForRead)
If Not IsDBNull(ent) Then
Dim axarae As Double = ent.Area
toal = toal + axarae
ed.WriteMessage(CStr(toal))
End If