How would I register an event handler that would detect the deletion of a sketch entity? I have a SketchLine with some associated text and I want to delete the text when the line is deleted.
Thanks
After thinking about this for a while I decided to try listening for ui.ActiveSelectionChanged events. I thought I would be able to detect when a labeled SketchLine was selected and then look for it after the selection changes to being nothing. If I couldn't find the SketchLine then I could assume it was deleted. I stored the entityToken of the SketchLine and then looked for it after the selection was cleared which can happen either by hitting ESC key, clicking on an empty part of the screen, or deleting the selected entity.
The problem I have is that when the SketchLine is deleted the findEntityByToken() function still returns a valid object in the ActiveSelectionChanged callback. Upon a second entrance into the callback the findEntityByToken() correctly fails to find the deleted SketchLine.
As a kludge I executed the SelectCommand again from with the callback if the selection was empty and the last thing selected was a labeled SketchLine and this worked. I was able to detect that the labeled SketchLine was deleted and then I was able to delete the corresponding label text.
So I'm not sure if occasionally executing the SelectCommand again within my callback will cause problems or if there is a way to update the deleted items within the callback so findEntityByToken() correctly cannot find the deleted item.
EDIT:
The above didn't really work too well. Retriggering the SelectCommand caused normal commands to abort.
The solution I came up with that seems to work well is the following:
I will call the sketch object that consists of a line with associated text a "LabeledLine" object (my name, not a Fusion thing)
This solution is working great for me at this point.
Can't find what you're looking for? Ask the community or share your knowledge.