Is there any way to cancel an event? I am hooking into the BeforeCommandRun event and watching for when a user tries to delete a sheet from a draft. I can hook into it OK but I cannot find any documentation on how to tell it not to proceed with the delete.
Posted by: jonathan brown
Post date: 3/13/2012 1:09:33 PM
It would be awesome if Solid Edge supported it, wouldn't it. I've needed this myself in the past but the API just doesn't support it. I tried to think out-of-the-box and come up with another way to do what you're wanting but I couldn't find anything useful.
Posted by: Jason Newell
Post date: 3/14/2012 6:02:20 PM
I tried to do the same with another event & failed as well (even when launching an exception).
The best thing I got was that user got a message like "action can't continue" which I hated.
My solution was to monitor the action & test if it is wrong and sitting on the after event handler if action was wrong => I've reverted it.
(for delete copy the file to tmp name if it should be deleted and than rename it to original name)
Posted by: joseph polk
Post date: 3/18/2012 7:13:58 AM
in the past I could successfully do the following in Assembly to avoid deleting a part:
1) Inside the BeforeCommandRun event, check if any of these commands are going to run and if there are objects in the SelectSet:
* 40212 (AssemblyEditDelete)
* 57635 (AssemblyEditCut)
2) Do some verifications on the SelectSet specific to your application and decide, if the parts in it can be deleted from the assembly or not.
3) If you DON'T want the objects to be deleted, simply clear the SelectSet and return from the event handler
For other environments, the "delete" commands vary and need to be updated.
Posted by: Martin Bernhard
Post date: 3/20/2012 4:41:16 AM
I have not tried this but ...
Most solid edge commands will cancel if the user hits the escape key. So you might be able to use the Windows SendInput API to send the escape key input to the application. If the command is one that does not immediately execute some action, theoretically this should cancel the command. If a dialog comes up and you know that, you may have to send two escape inputs, one for the dialog and one for the command if it does something after the dialog is dismissed (such as locate). Of course this will only work if the command is going to process windows messages before doing what it does. If sending escape to the app window doesn't work, send it to the active view and it will be routed to the active command. Use post message, not send message as when the beforecommandrun event is fired I don't think the command is processing input yet.
Of course there is also WM_CANCEL, which might help in some cases (I think menus react to it as do some controls and possibly dialogs). You probably have to make sure the message is posted/sent to the correct window though making this one a bit harder to use.
I have not used SendInput to send keyboard input but I have used it to send mouse inputs. If you ever saw the old command assistant/finder show the user how to navigate the old menus (pre ST) to find a command when the user hovered over a command in the assistant's window, SendInput was how that was accomplished (I basically sent mouse click events where the mouse point was over the menu entry I needed Windows to expand causing the menu to drop down so I could highlight the menu entry with the command on it).
Posted by: R.D. Holland
Post date: 3/23/2012 10:43:02 AM