.NET

Reply
Active Contributor
greg
Posts: 33
Registered: ‎02-13-2013
Message 1 of 14 (398 Views)
Accepted Solution

Failed to get selectionresult

398 Views, 13 Replies
08-28-2013 07:07 PM

I have an application that utilizes this code to select entities

 

 

For x = 0 To SelectionSetEntitiesBindingSource.Count - 1
     ObjectIDs(x) = ObjectIdFromHandle(myDocDB, SelectionSetEntitiesBindingSource(x)("ACADHandle").ToString)
Next

Autodesk.AutoCAD.Internal.Utils.SelectObjects(ObjectIDs)

 

 

And then this code to build a selection set from those entities

 

    Public Function GetSelectionSet() As SelectionSet
        Dim myDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim myDocDB As Database = myDoc.Database
        Dim ed As Editor = myDoc.Editor

        Dim prObjectSelectionRes As PromptSelectionResult
        prObjectSelectionRes = ed.SelectImplied()
        If prObjectSelectionRes.Status = PromptStatus.OK Then
            GetSelectionSet = prObjectSelectionRes.Value
        Else
            MsgBox("An error occurred getting the selection set.", vbOKOnly, "Error")
            Exit Function
        End If
    End Function

 

This works fine for a while, but eventually the second part of the code failes at prOjectSelectionRes = ed.selectImplied...or rather not fails but returns error -5001.

 

This appears to be directly related to the number of times I call this function as though there is a limit to the number of sets you can create in an instance of Autocad...or something similar.

 

These entities are being retrieved from a database which is the reason for the loop in the first part.  I execute the code and it will run for a while going through the different tables in the db.

 

Any help is greatly appreciated.

Thanks!

Active Contributor
greg
Posts: 33
Registered: ‎02-13-2013
Message 2 of 14 (369 Views)

Re: Failed to get selectionresult

08-29-2013 05:03 AM in reply to: greg

Just to add a bit more.

 

It appears when I get out of the command and I select something on screen I can not hit the esc key to cancel the selection...really weird behavior within model space until I change to a layout and back to model space does it fix itself.

*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 3 of 14 (359 Views)

Re: Failed to get selectionresult

08-29-2013 06:22 AM in reply to: greg

This is the method I've used, it also lets me hit the space bar to repeat the command.

 

Private Sub btnSelectBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectBlock.Click
    If Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Count = 0 Then
        Exit Sub
    End If
 
    curDoc.SendStringToExecute(Chr(27), False, False, False)
    curDoc.SendStringToExecute("MyCommand" & vbCr, False, False, False)
    Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()

End Sub

<CommandMethod("MyCommand")> _
Public Sub selectBlock()
    ....
End Sub

 

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



(defun botsbuildbots() (botsbuildbots))
Active Contributor
greg
Posts: 33
Registered: ‎02-13-2013
Message 4 of 14 (351 Views)

Re: Failed to get selectionresult

08-29-2013 06:55 AM in reply to: arcticad

Thanks for the response but not sure how that would help me.

 

Workflow of the application:

  • Application is executed
  • Form opens with various settings.
  • Button is clicked
  • Application makes connection to external database table as a binding source
  • Application loops through binding source where Handle is stored of the drawing objects.
  • Application selects drawing entites based the handles from the bindingsource.
  • Application performs action on entities
  • Application makes another connect to external database for another table table and sets as binding source
  • Application loops through binding source where Handle is stored of the drawing objects.
  • Application selects drawing entites based the handles from the bindingsource.
  • Application performs action on entities
  • This process continues through many different tables..right now about 5 or so but will most likely be added to as time goes on.

 

I dont need to rexecute the command with the space bar..not a concern really.

 

Any other ideas?

 

Thanks

*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 5 of 14 (340 Views)

Re: Failed to get selectionresult

08-29-2013 07:33 AM in reply to: greg

    <CommandMethod("MyCommand", CommandFlags.Modal Or CommandFlags.UsePickSet Or CommandFlags.Redraw)> _
    Public Sub MyCommand()
        GetSelectionSet()
    End Sub

 

This worked for getting the implied selection set.

 

There is a limit of 128 selection set open at one time.

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



(defun botsbuildbots() (botsbuildbots))
Active Contributor
greg
Posts: 33
Registered: ‎02-13-2013
Message 6 of 14 (330 Views)

Re: Failed to get selectionresult

08-29-2013 07:46 AM in reply to: arcticad

if you meant I should include "CommandFlags.Modal Or CommandFlags.UsePickSet Or CommandFlags.Redraw" on the original entry...I just did that and it did not fix the issue.

 

Thanks,

*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 7 of 14 (323 Views)

Re: Failed to get selectionresult

08-29-2013 08:03 AM in reply to: greg

http://spiderinnet1.typepad.com/blog/2012/09/autocad-net-count-limit-of-available-selection-sets.htm...

 

 

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



(defun botsbuildbots() (botsbuildbots))
Active Contributor
greg
Posts: 33
Registered: ‎02-13-2013
Message 8 of 14 (306 Views)

Re: Failed to get selectionresult

08-29-2013 03:20 PM in reply to: arcticad

Thank you!  It appears this may be the problem.  However I am still in the process of altering my code to explicitly dispose of all selectionsets that are created.  

 

I will let you know.

 

Thanks again.

Active Contributor
greg
Posts: 33
Registered: ‎02-13-2013
Message 9 of 14 (297 Views)

Re: Failed to get selectionresult

08-29-2013 06:25 PM in reply to: greg

So I took the code in the link you provided and modified it a bit to use the general functionality that I am using and this replicates the error I am receiving exactly.  Bombs out at 128 which I suppose makes sense.  The problem is that I am not sure why. I am disposing my selection set with each run through the loop.  Is there something else?

 

    <CommandMethod("TestSelectionSetCountLimit2", CommandFlags.Modal Or CommandFlags.UsePickSet Or CommandFlags.Redraw)> _
    Public Sub TestSElectionSetCountLimit2()
        Dim myDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim ed As Editor = myDoc.Editor

        Try
            For i = 0 To 130
                Dim ObjectIDs(0) As ObjectId

                ObjectIDs(0) = ObjectIdFromHandle(db, "A33DC")

                Autodesk.AutoCAD.Internal.Utils.SelectObjects(ObjectIDs)

                Dim prObjectSelectionRes As PromptSelectionResult
                prObjectSelectionRes = ed.SelectImplied()
                If prObjectSelectionRes.Status = PromptStatus.OK Then
                    Dim ss As SelectionSet
                    ss = prObjectSelectionRes.Value
                    If ss IsNot Nothing Then
                        ed.WriteMessage(vbLf & "The #{0} SS is good and has {1} entities.", i + 1, ss.Count)
                        ss.Dispose()
                    Else
                        ed.WriteMessage(vbLf & "The #{0} SS is bad!", i + 1)
                    End If
                Else
                    ed.WriteMessage(vbLf & "The #{0} SS is bad!", i + 1)

                End If
            Next
        Catch ex As System.Exception
            ed.WriteMessage(ex.ToString())
        End Try
    End Sub

 

Active Contributor
greg
Posts: 33
Registered: ‎02-13-2013
Message 10 of 14 (268 Views)

Re: Failed to get selectionresult

08-30-2013 04:07 AM in reply to: greg

I should also add that you can easily duplicate the error by just replacing the handle with one from your drawing and using the below "ObjectIDfromHandle" function I forgot to include.

    Public Shared Function ObjectIdFromHandle(db As Database, strHandle As String) As ObjectId
        Dim nHandle As Int32 = Int32.Parse(strHandle, Globalization.NumberStyles.AllowHexSpecifier)
        Dim handle As New Handle(nHandle)
        Dim ids(0) As ObjectId
        ids(0) = db.GetObjectId(False, handle, 0)
        Return ids(0)
        'Return db.GetObjectId(False, handle, 0)
    End Function

 Thanks,

Announcements
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.