This post takes the sample code shown in the last entry, converts it to VB.NET and adds in some code to access specific entity properties rather than simply calling list().
I won't step through the code this time, but here's the section of code that gets and dumps out the various entity properties:
Dim ent As Entity = CType(tr.GetObject(objId, OpenMode.ForRead), Entity)
' This time access the properties directly
ed.WriteMessage(vbLf + "Type: " + ent.GetType().ToString)
ed.WriteMessage(vbLf + " Handle: " + ent.Handle().ToString)
ed.WriteMessage(vbLf + " Layer: " + ent.Layer().ToString)
ed.WriteMessage(vbLf + " Linetype: " + ent.Linetype().ToString)
ed.WriteMessage(vbLf + " Lineweight: " + ent.LineWeight().ToString)
ed.WriteMessage(vbLf + " ColorIndex: " + ent.ColorIndex().ToString)
ed.WriteMessage(vbLf + " Color: " + ent.Color().ToString)
ent.Dispose()
We're using the ToString property to help generate a string to display through the AutoCAD command-line - otherwise the code should be fairly obvious.
Here's the complete VB.NET sample:
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Namespace SelectionTest
Public Class PickfirstTestCmds
' Must have UsePickSet specified
<CommandMethod("PFT", _
(CommandFlags.UsePickSet _
Or CommandFlags.Redraw _
Or CommandFlags.Modal))> _
Public Shared Sub PickFirstTest()
Dim doc As Document = _
Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Try
Dim selectionRes As PromptSelectionResult
selectionRes = ed.SelectImplied
' If there's no pickfirst set available...
If (selectionRes.Status = PromptStatus.Error) Then
' ... ask the user to select entities
Dim selectionOpts As PromptSelectionOptions
selectionOpts = New PromptSelectionOptions
selectionOpts.MessageForAdding = _
vbLf & "Select objects to list: "
selectionRes = ed.GetSelection(selectionOpts)
Else
' If there was a pickfirst set, clear it
ed.SetImpliedSelection(Nothing)
End If
' If the user has not cancelled...
If (selectionRes.Status = PromptStatus.OK) Then
' ... take the selected objects one by one
Dim tr As Transaction = _
doc.TransactionManager.StartTransaction
Try
Dim objIds() As ObjectId = _
selectionRes.Value.GetObjectIds
For Each objId As ObjectId In objIds
Dim ent As Entity = _
CType(tr.GetObject(objId, OpenMode.ForRead), Entity)
' This time access the properties directly
ed.WriteMessage(vbLf + "Type: " + _
ent.GetType().ToString)
ed.WriteMessage(vbLf + " Handle: " + _
ent.Handle().ToString)
ed.WriteMessage(vbLf + " Layer: " + _
ent.Layer().ToString)
ed.WriteMessage(vbLf + " Linetype: " + _
ent.Linetype().ToString)
ed.WriteMessage(vbLf + " Lineweight: " + _
ent.LineWeight().ToString)
ed.WriteMessage(vbLf + " ColorIndex: " + _
ent.ColorIndex().ToString)
ed.WriteMessage(vbLf + " Color: " + _
ent.Color().ToString)
ent.Dispose()
Next
' Although no changes were made, use Commit()
' as this is much quicker than rolling back
tr.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(ex.Message)
tr.Abort()
End Try
End If
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(ex.Message)
End Try
End Sub
End Class
End Namespace