Hi,
I would like to add additional entities to the selection if any of the selected entities contains a an xdata value.
If I put the condition into the ImpliedSelectionChanged reactor I imagine will probably loop back on itself.
Is this something that might be possible?
Solved! Go to Solution.
Solved by DiningPhilosopher. Go to Solution.
Thanks again!
Editor events don't seem to appear in the AutoCAD NET Developers guide that I've been looking up.
I have a couple of things to try to bullet proof the event handlers. I keep a count of every transaction open and closed (trcnt as integer).
The SelectionAdded event handler is one that doesn't appear to cope with transactions. Must be some internal calls that uses the SelectionAdded event, starts the transaction but doesn't dispose it. This is without any code between StartTransaction and End Using that might cause any disruption.
Is there a way to keep an eye on the selected objects xdata without opening a transaction?
Dim ss As SelectionSet = e.AddedObjects For Each so As SelectedObject In ss ? Next
I think I already mentioned in another thread that StartOpenCloseTransaction() returns a transaction that can be used in event handlers.
It's a little confusing. The following creates a message box saying that the trcnt variable is not zero when it should be.
I've shelled down to just the one handler to make sure that there were no others that may have been causing it.
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput <Assembly: ExtensionApplication(GetType(testClass))> Public Class testClass Implements IExtensionApplication Private DocMan As DocumentCollection Private trcnt As Integer Private PauseEvents As Boolean Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize Dim doc As Document = Application.DocumentManager.MdiActiveDocument InitializeActiveDocument(doc) End Sub Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate End Sub Sub InitializeActiveDocument(ByVal doc As Document) Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Using trans As OpenCloseTransaction = db.TransactionManager.StartOpenCloseTransaction() : trcnt = trcnt + 1 Try AddHandler ed.SelectionAdded, AddressOf ed_SelectionAdded trans.Commit() : trcnt = trcnt - 1 : If trcnt > 0 Then MsgBox("TRCNT>0") If trcnt <> 0 Then MsgBox("TRCNT " & trcnt & " Init active doc") Catch ex As Autodesk.AutoCAD.Runtime.Exception MsgBox("Exception:" + ex.Message) End Try End Using End Sub Private Sub ed_SelectionAdded(ByVal sender As Object, ByVal e As SelectionAddedEventArgs) Dim db As Database = HostApplicationServices.WorkingDatabase Using tr As OpenCloseTransaction = db.TransactionManager.StartOpenCloseTransaction() trcnt = trcnt + 1 trcnt = trcnt - 1 : If trcnt > 0 Then MsgBox("ed_SelectionAdded TRCNT>0") End Using End Sub End Class
Sorry, your code and the test it does which you are confused about makes no sense at all.
The only thing you have to do is start the transaction (in the event handler), use it to open objects, and then commit the transaction before the event handler returns, and there is no point to or need for tracking (I'm not sure what it is you're tracking in the first place).
My appologies.
I discovered that I wasn't disabling the ImpliedSelectionChanged event handler within the SelectionAdded handler.
The transaction count was useful though in that it allerted me that this was the problem.
Thanks for your help and sorry for the useless code above.
I see what you mean by AutoCAD running like a snail on this sort of handler. It reacts to mouseover of every entity. I just want to know if the entity is selected.
Is there another way other than looping back on ImpliedSelectionChanged?
@SRSDS wrote:I see what you mean by AutoCAD running like a snail on this sort of handler. It reacts to mouseover of every entity. I just want to know if the entity is selected.
Is there another way other than looping back on ImpliedSelectionChanged?
AFAIK, the SelectionAdded event doesn't fire when hovering over an entity. It fires only when the user has selected some objects, which could be at the Command prompt with the implied selection or within a command that prompts for a selection.
It seems to unfortunately. e.Selection is contains no objects.
It's a rare case that I need to use it. I'll prompt the user that the other entity needs to be modified and not the one selected.
The selected objects are in the AddedObjects property, not the SelectionSet property.
Read the documentation, and search here for examples of its use.
I 've ended up using the EnteringQuiescentState event to do this.
I couldn't understand the errors the SelectionAdded event was generating or why it was firing so many times.
Thanks again and sorry for any trouble there.
Can't find what you're looking for? Ask the community or share your knowledge.