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

editor SelectionAdded event

2 REPLIES 2
Reply
Message 1 of 3
BrentBurgess1980
1057 Views, 2 Replies

editor SelectionAdded event

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?

2 REPLIES 2
Message 2 of 3
leefsma
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

 

Message 3 of 3
BrentBurgess1980
in reply to: leefsma

Thanks for the info. Will try it out

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