.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Identifying Object Type String for Selection Set Filter

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
wein3967
1418 Views, 2 Replies

Identifying Object Type String for Selection Set Filter

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 = _
              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 obj As Object = _
                              tr.GetObject(objId, OpenMode.ForRead)
                            Dim ent As Entity = _
                              CType(obj, Entity)

                            Stop
                            'MsgBox(ent.ColorIndex)


                            ' 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:  " + _
                                  circ.Center.ToString)
                                ed.WriteMessage(vbLf + "  Radius:  " + _
                                  circ.Radius.ToString)
                            End If
                            obj.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

  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.

2 REPLIES 2
Message 2 of 3
norman.yuan
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.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
wein3967
in reply to: norman.yuan

Norman,

 

Thanks. Just what I was looking for!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost