VB.NET Selection Set samples

By Philippe Leefsma

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

   &#160
;       
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

 


Comments

3 responses to “VB.NET Selection Set samples”

  1. xanhnhnn280683@gmail.com Avatar
    xanhnhnn280683@gmail.com

    Hello forum, I have a small question, would the guide you
    I have five single foundation construction civil pile are the same, in one drawing , so you write code that calculate the number of single foundation construction

  2. Abhilash D K Avatar
    Abhilash D K

    Hi,
    Can anybody tell me what may be the equivalent code in VB.NET for the below code in ARX:
    acutBuildList(RTDXF0, L”SHAPE”, NULL)
    I tried the following It did not work :
    Dim acTypValAr(0) As TypedValue
    acTypValAr.SetValue(New TypedValue(DxfCode.Start, “SHAPE”), 0)
    Please help

  3. Hi thank you Philippe this code shows how to obtain the handle to an object – but do you know how to select the object itself to allow the user (as opposed to the .net plugin) to then manipulate it within autocad?

Leave a Reply to BenCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading