GetSelction is bypassed

GetSelction is bypassed

Anonymous
Not applicable
533 Views
4 Replies
Message 1 of 5

GetSelction is bypassed

Anonymous
Not applicable

i have two ways of selection LINES, one is All in dwg (this works), second is by selection on screen using getselection.  This is not allowing user to select anything, it just runs right through with out allowing user to grab anything. 

 

Dim

myLINE As TypedValue

myLINE = New TypedValue(0, "LINE)

 

Dim myFilter AsNewSelectionFilter(myLine)

 

Dim ed AsEditor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

 

Dim myPSR AsPromptSelectionResult

 

If RadioButton1.Checked = TrueThen''Not working

myPSR = ed.GetSelection(myFilter)

Else''Yes working

myPSR = ed.SelectAll(myFilter)

EndIf

 

0 Likes
534 Views
4 Replies
Replies (4)
Message 2 of 5

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

"not working" is not the best description possible 😉

 

Let us know:

  • what "not working" means for you. Error-message, ...
  • where comes "RadioButton1" from? Has your code access to the instance of the form where this control is placed? Can you make a breakpoint and watch the value RadioButton1.Checked? What is the value ....

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 5

Anonymous
Not applicable

sorry about that, i was frustrated at that time.

 

No error message.  I put break points at IF point, steped down to the Getselection section then it step right over it to the end if.  it was there to run, then never ran, acted as if, i had already selected objects and goes to next section of code.  i have tried running the getselection by itself else where and does same thing.  never goes to the screen to allow user to select objects.

 

0 Likes
Message 4 of 5

chiefbraincloud
Collaborator
Collaborator

two possible's.

 

1) If the command method you called to run this code has the UsePickSet flag set (and maybe Redraw, not sure about that one), and there are objects selected in the drawing window when the command is fired, then a subsequent call to GetSelection will return those objects in a selection set, without there being any user interaction.  That is designed behavior.

 

2) I searched my code quickly, and I did not find one occurance where I call GetSelection from inside form code.  I am assuming that you are calling this from inside form code, because there is no form qualifier on RadioButton1.  I would put in a call to Me.Hide, then do the GetSelection.  Then, if you need the form to still be showing after this code completes, then put in a call to Me.Show.

 

For what it is worth, I modified a place in my code to try to do a GetSelection from inside the form code, without calling Me.Hide and Me.Show, and it still worked as it should, and even though I displayed the form with ShowModalDialog, the form disappeared and reappeared as if I had called Me.Hide and Me.Show.

 

Perhaps the problem might come from using Form.ShowDialog instead of Application.ShowModalDialog? I just tried that too, and it still worked, so I can not seem to recreate the problem.

 

Meant to say without any user interaction:

Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 5 of 5

arcticad
Advisor
Advisor

Try this code

 

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput

Public Class test

    <CommandMethod("getline")> _
    Public Shared Sub SelectLineOnly()
        Dim activeDocument As Document = Application.DocumentManager.MdiActiveDocument
        Dim activeDB As Database = activeDocument.Database

        Dim ed As Editor = activeDocument.Editor

        Using db As Database = HostApplicationServices.WorkingDatabase()
            Using trans As Transaction = db.TransactionManager.StartTransaction()
                Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
                Using lock As DocumentLock = dwg.LockDocument

                    Dim selectionTypeValue As TypedValue() = New TypedValue(0) {}
                    selectionTypeValue.SetValue(New TypedValue(CInt(DxfCode.Start), "LINE"), 0)

                    Dim selectionFilter As New SelectionFilter(selectionTypeValue)
                    Dim getSelectionResult As PromptSelectionResult
                    getSelectionResult = ed.GetSelection(selectionFilter)

                    ' If selection actually contains something
                    If getSelectionResult.Status = PromptStatus.OK Then
                        Dim selectionSet As SelectionSet = getSelectionResult.Value

                        For Each selectedObject As SelectedObject In selectionSet
                            If selectedObject IsNot Nothing Then
                                Dim selectedEntity As Entity = TryCast(trans.GetObject(selectedObject.ObjectId, OpenMode.ForWrite), Entity)
                            End If
                        Next
                        trans.Commit()
                    End If
                End Using
            End Using
        End Using

    End Sub

End Class

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes