Cancel copy or delete

Cancel copy or delete

SRSDS
Advisor Advisor
1,838 Views
10 Replies
Message 1 of 11

Cancel copy or delete

SRSDS
Advisor
Advisor

Is it possible to cancel the copying or deletion of entities?

Ie a OK/Cancel message box asks the user if they are sure.

 

 

 

 

0 Likes
Accepted solutions (1)
1,839 Views
10 Replies
Replies (10)
Message 2 of 11

SRSDS
Advisor
Advisor

This one just took a bit of extra thought.

   Application.DocumentManager.MdiActiveDocument.SendStringToExecute("UNDO 1 ", True, False, True)
0 Likes
Message 3 of 11

norman.yuan
Mentor
Mentor

It seems your solution does not meets your original requirement of showing "OK/Cancel" before deleting. Obviously, you can use "UNDO" to get things back after they are deleted, if user answers "Cancel".

 

Although I'd think that with powerful "UNDO" in AutoCAD in place, asking "Yes/No" confirmation before copying/deleting would be bad/hated by users in vast majority of cases, but you might have your legitimate reason(s). So, when do you ask for user confirmation - whenever erasing is to occur? Or only when your specifically coded process is to do erasing (then, why your code let it happen without asking confirmation, and then only "UNDO" it back by asking confirmation after the fact of erasing)? Just curious.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 11

SRSDS
Advisor
Advisor

Hi Norman,

The undo thing is not ideal.

 

Every time an entity is copied or deleted the application gives the user two options of how they want data associated with those entities to be handled. 

A modal form with two buttons and the only way to close it is to press one of those buttons.

I'd like a cancel button which stops the copy or delete.

 

I guess with copy I delete the copied entities. And if it's delete then I somehow put those entities back into the drawing. I'd really appreciate any better ideas.

 

 

 

 

 

0 Likes
Message 5 of 11

norman.yuan
Mentor
Mentor

It is still not clear to me that how the modal form is triggered. My curiosity was how do you manage to ask for confirmation, before or after the fact. It seems you shows it AFTER the fact of copying/erasing (handling some events. such as CommandEnded?). Hopefully you have made your event handler(s) only deal with very specific cases of deleting, so user would not get annoyed too much.

 

I'd think it is possible to ask for confirmation before erasing, while for copying, things could be a bit complicated because user can either use AutoCAD built-in COPY command, or use Ctl+C (windows clipboard), for which AutoCAD behaves a bit differently. 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 11

SRSDS
Advisor
Advisor

The form is triggered by the DeepCloneEnded event for a copy and CommandEnded for erase.

DeepCloneEnded seems to capture all copy events.

 

I could change the erase to CommandWillStart. How would I then cancel the erasure of entites?

 

0 Likes
Message 7 of 11

norman.yuan
Mentor
Mentor

I have an idea of knowing exact what entity is to be erased and asking confirmation before the erasing, but need a bit time to give it a try. I am a bit busy right now and will get back once I tried my idea, be the outcome good or bad 😒

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 8 of 11

SRSDS
Advisor
Advisor

Thanks Norman. Really appreciate the help.

0 Likes
Message 9 of 11

norman.yuan
Mentor
Mentor
Accepted solution

@SRSDS I finally spent some time and worked out something. That is quite some code. So, as usual, in order to make it easier for anyone who is interested in to read, I posted it my blog here, including video clips and source code. Due to limited time and to make things a bit simple, I only dealt with confirmed erasing.

 

Hope it would give you some ideas.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 10 of 11

Octal7
Explorer
Explorer

Have you looked into the TransformOverrule?  You can override methods like CloneMeForDraggingExplode and TransformBy.  Also check the ObjectOverrule where you can override the Erase method.

0 Likes
Message 11 of 11

SRSDS
Advisor
Advisor

Norman,

Thank you so much. I've yet to go through it all in detail but great to know there's a solution.

Thank you!

 

0 Likes