Implementing Custom Parent Command Repeat with Space/Enter and Single Undo for Entire Custom Parent Command

Implementing Custom Parent Command Repeat with Space/Enter and Single Undo for Entire Custom Parent Command

santhoshr151194
Contributor Contributor
213 Views
1 Reply
Message 1 of 2

Implementing Custom Parent Command Repeat with Space/Enter and Single Undo for Entire Custom Parent Command

santhoshr151194
Contributor
Contributor

I'm developing an AutoCAD plugin using .NET API that needs to implement two specific behaviors:

Command Repetition: I have a custom parent command which uses AutoCAD's built-in command to create polyline internally, then adds related entities (text) and data. When my custom parent command completes and the user presses Space or Enter (standard AutoCAD behavior for repeating commands), I want my entire custom parent command to repeat, not just the last operation.

Single Undo for entire Custom Parent Command: My custom parent command uses AutoCAD built-in commands internally and performs operations across multiple transactions with user interactions between them. As of now, the user has to press Ctrl+Z multiple times to undo all operation in custom parent command. I need all operations to be undo in a single undo step.

My command workflow:
- Create polyline using AutoCAD's built-in command (SendStringToExecute)
- Create text entity in the Command Ended callback (to display polyline name) in one transaction
- Creating mapping between polyline and text entities in another transaction

When the user presses Space/Enter, the entire sequence in my custom parent command should repeat.
When the user executes Undo, all operations in my custom parent command should be undone in a single step(Text and Polyline should be deleted).

0 Likes
214 Views
1 Reply
Reply (1)
Message 2 of 2

ActivistInvestor
Mentor
Mentor

Sorry to have to say this but the code you show is completely FUBAR.

 

You are using SendStringToExecute() along with CommandEnded event handlers, which is a horror show of a kludge that causes more problems than it solves. This API does not execute the command strings it is passed until the managed code that calls it has exited and returned control to AutoCAD. You need to learn to use the API properly, and avoid kludges like SendStringToExecute(), and I don't see much hope for fixing anything that uses that API. The Editor's Command() method is what should be used to script AutoCAD commands. If you are initiating your code from the application context (e.g., a button on a Palette, ribbon, or modeless input) you can execute code in the document context where the Command() method can be used.

 

0 Likes