The attached zip file has a VB.NET project that demonstrates how to select objects using .NET and COM Interop. It has three commands :
SELSET: Demonstrates creating a selection set using AutoCAD Interop.
SELLINE: Demonstrates using the ActiveX GetEntity function to select and query a single entity (a line in this example).
NETSELECT: Shows how to select a AutoCAD entities using the native .NET Select function. Here is the code from this command:
<Autodesk.AutoCAD.Runtime.CommandMethod("NETSELECT")> _
Public Sub NetSel()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim pSelRes As PromptSelectionResult = ed.SelectAll()
Dim dbObj As DBObject
Using tr As Transaction = db.TransactionManager.StartTransaction
‘ Basic error handling
 
; Try
If (pSelRes.Status <> PromptStatus.OK) Then
Return
End If
Dim objIdArray() As ObjectId = pSelRes.Value.GetObjectIds()
For Each objId As ObjectId In objIdArray
dbObj = tr.GetObject(objId, OpenMode.ForRead)
ed.WriteMessage(dbObj.GetType.ToString + vbCrLf)
Next
tr.Commit()
Catch ex As Exception
ed.WriteMessage(ex.ToString())
tr.Abort()
End Try
End Using
End Sub

Leave a Reply to BenCancel reply