C# COM Escaping current command

C# COM Escaping current command

Anonymous
Not applicable
2,275 Views
5 Replies
Message 1 of 6

C# COM Escaping current command

Anonymous
Not applicable

Is it possible to have a line of code that interrupts the current command in AutoCAD, like the equivalent of pressing 'escape' on the keyboard?

 

For example, if during runtime the user has clicked somewhere on the screen in AutoCAD and is currently creating a selection window, I would like to cancel that command and continue with my code.

Accepted solutions (1)
2,276 Views
5 Replies
Replies (5)
Message 2 of 6

Ed__Jobe
Mentor
Mentor

You don't need code. Just start your command macro in the cui with "^C^CmyCommand". That will issue two {ESC} before starting myCommand.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 6

Anonymous
Not applicable

What I'm using isn't a command macro, it's an out of process program that requires the user to select a point in AutoCAD before returning to my program, but the COM calls break if it's in the middle of a selection. 

 

Just wondering if there was a way to get rid of that selection programmatically before continuing and avoid relying on the user to cancel their selection.

0 Likes
Message 4 of 6

Ed__Jobe
Mentor
Mentor

You can mimic the macro in my first post using the vba SendKeys method. See the vba Help on how to use it.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 6

Anonymous
Not applicable

If I try to do the SendCommand method while it's in the middle of a command e.g. selecting, I get the exception "Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)", any idea how to get around this?

0 Likes
Message 6 of 6

Ed__Jobe
Mentor
Mentor
Accepted solution

I said use SendKeys, not SendCommand. In C# it should be under System.Windows.Forms.SendKeys. You just need to make sure you have the right window to send the keys to. It needs to be the acad application window.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes