Posts: 17
Registered: ‎02-29-2012
Message 1 of 3 (400 Views)
Accepted Solution

Identifying Object Type String for Selection Set Filter

400 Views, 2 Replies
05-25-2013 04:52 PM

I am currently running AutoCAD 2011. I have a specific problem, but I am also looking for a solution to the general issue as well.


Specifically, I am trying to identify the object type of a Polyface Mesh for use in a Selection Set filter. For example, a 3D solid will return "Solid3D" from the GetType method, but for the selection set filter I have to use the string "3DSOLID" in order for it to filter correctly. The GetType method for my Polyface Mesh returns PolyFaceMesh, which does not work for my Selection Set filter.


In general, I'd like to have a code that will just tell me what the proper type string is for use in filters. I frequently use the following code (copied from a developer's post) to help me out, but I still can't find the method that will return the the information I am looking for here.


Public Class WhoAmI

        ' Must have UsePickSet specified
        <CommandMethod("WAI", _
          (CommandFlags.UsePickSet _
            Or CommandFlags.Redraw _
            Or CommandFlags.Modal))> _
        Public Shared Sub ObjectProperties()
            Dim doc As Document = _
            Dim ed As Editor = doc.Editor
                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)
                    ' If there was a pickfirst set, clear it
                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 = _
                        Dim objIds() As ObjectId = _
                        For Each objId As ObjectId In objIds
                            Dim obj As Object = _
                              tr.GetObject(objId, OpenMode.ForRead)
                            Dim ent As Entity = _
                              CType(obj, Entity)


                            ' This time access the properties directly
                            ed.WriteMessage(vbLf + "Type:        " + ent.GetType().ToString)
                            ed.WriteMessage(vbLf + "  ObjectID:    " + ent.ObjectId().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)
                            ' Let's do a bit more for circles...
                            If TypeOf (obj) Is Circle Then
                                ' Let's do a bit more for circles...
                                Dim circ As Circle = CType(obj, Circle)
                                ed.WriteMessage(vbLf + "  Center:  " + _
                                ed.WriteMessage(vbLf + "  Radius:  " + _
                            End If
                        ' Although no changes were made, use Commit()
                        ' as this is much quicker than rolling back
                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                    End Try
                End If
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
            End Try
        End Sub

  Here is the code I use for implementing the Selection Set filter. The FilterString is the value I am looking for.

Private Function GetSelectionSet(ByVal FilterString As String) As ObjectId()

            '' Get the current document editor
            Dim acDocEd As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

            '' Create a TypedValue array to define the filter criteria
            Dim acTypValAr(0) As TypedValue
            acTypValAr.SetValue(New TypedValue(DxfCode.Start, FilterString), 0)

            '' Assign the filter criteria to a SelectionFilter object
            Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)

            '' Request for objects to be selected in the drawing area
            Dim acSSPrompt As PromptSelectionResult
            acSSPrompt = acDocEd.GetSelection(acSelFtr)

            '' If the prompt status is OK, objects were selected
            If acSSPrompt.Status = PromptStatus.OK Then
                Dim acSSet As SelectionSet = acSSPrompt.Value
                'Dim idarray As ObjectId() = acSSet.GetObjectIds()

                Return acSSet.GetObjectIds()

            End If

        End Function

 Thanks a bunch.

*Expert Elite*
Posts: 980
Registered: ‎04-27-2009
Message 2 of 3 (386 Views)

Re: Identifying Object Type String for Selection Set Filter

05-25-2013 09:43 PM in reply to: wein3967

ObjectId.ObjectClass.DxfName is what yuo are looking for.


For example, if you get the ObjectId of a BlockReference, its ObjectClass.DxfName property will have value "INSERT", which can be used as selectionset filter.

Posts: 17
Registered: ‎02-29-2012
Message 3 of 3 (361 Views)

Re: Identifying Object Type String for Selection Set Filter

05-26-2013 08:09 AM in reply to: norman.yuan



Thanks. Just what I was looking for!

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.