.NET

Reply
Mentor
BrentBurgess1980
Posts: 166
Registered: ‎06-16-2008
Message 1 of 3 (337 Views)

editor SelectionAdded event

337 Views, 2 Replies
05-31-2011 08:37 PM

I am trying to get a list of selected entities and their layers, but I want to capture it from the editor, not a command.

 

I currently have

 

    Private Sub ed_SelectionAdded(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.EditorInput.SelectionAddedEventArgs) Handles ed.SelectionAdded
        Try
            For Each objid As ObjectId In e.AddedObjects.GetObjectIds
                Using tr As Transaction = ed.Document.TransactionManager.StartTransaction
                    Dim ent As Entity = tr.GetObject(objid, OpenMode.ForRead)
                    ed.WriteMessage(vbLf & objid.ObjectClass.DxfName & " is on " & ent.Layer)
                End Using
            Next
        Catch ex As Autodesk.AutoCAD.Runtime.Exception
        End Try
    End Sub

 

but when select a circle on Layer 1, I get the result below in the commandline

 

CIRCLE is on Layer1
CIRCLE is on Layer1
CIRCLE is on Layer1
CIRCLE is on Layer1
CIRCLE is on Layer1
CIRCLE is on Layer1
Command:
CIRCLE is on Layer1

 

If I hover over the circle while it is selected, it also treates it as a selection.

 

Can someone point me in the right direction?

Contributor
leefsma
Posts: 18
Registered: ‎05-19-2011
Message 2 of 3 (302 Views)

Re: editor SelectionAdded event

06-07-2011 04:19 AM in reply to: BrentBurgess1980

Hi,

 

SelectionAdded is called multiple times during PICKFIRST selection, whether you are calling SelectAll inside it or not. it is as designed. If a command starts the selection (i.e. not PICKFIRST) then SelectionAdded is only called once per each selection change.

 

One suggestion depending on what you are looking for is to use Document.ImpliedSelectionChanged event to monitor PICKFIRST selection change – this is only fired once after a selection change.

However, if you also want to monitor when the user removes entities from the selection so that you would also remove related objects from the selection, then you would need to keep track of the selection set, so you can see what the user removed from the selection. And if you keep track of the selection you might as well keep listening to SelectionAdded all the time, and if the selection did not change, then just return from it. This should not cause too much overhead.

 

I hope it helps.

 

 

Philippe Leefsma
Developer Consultant
Developer Technical Services
Global Subscription & Support
 

Autodesk EMEA

  

www.autodesk.com/joinadn

 

Mentor
BrentBurgess1980
Posts: 166
Registered: ‎06-16-2008
Message 3 of 3 (282 Views)

Re: editor SelectionAdded event

06-07-2011 09:56 PM in reply to: leefsma

Thanks for the info. Will try it out

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.