Disable Saving While Plugin is Running

Disable Saving While Plugin is Running

drobertsY4GL3
Enthusiast Enthusiast
681 Views
4 Replies
Message 1 of 5

Disable Saving While Plugin is Running

drobertsY4GL3
Enthusiast
Enthusiast

What are some example methods I might use to disable and re-enable all save functionality for a drawing (quick save, save-as, autosave, etc.) My plugin needs to disable saving while it is running.

 

 

0 Likes
Accepted solutions (1)
682 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

You might as well provide more details of your case. You need to explain how your plugin loads and runs, and what exactly "running" means. Does the plugin always run as soon as the DLL is loaded (for example, the plugin starts custom Overrule once loaded, which might be considered "always running", a kind of. Or, your code only actually runs when a command method is called. So, explain in what scenario/why you need to disable saving (or actually you just want to disable "Save/SaveAs" command in certain situation?

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

drobertsY4GL3
Enthusiast
Enthusiast

Sure, Let me clarify.

 

The plugin is a C# dll with an entry point command method that shows a modeless wpf window, using a mvvm pattern.

I would like to run a method that blocks saving, until I choose to unblock it by running another method. "While plugin is running" would probably mean the save block method is run on window loaded, and the save unblock method is run on window closed. 


0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor
Accepted solution

Still not fully knowing your case. But if your goal is to not allow the drawing to be saved by user (executing command "qsave/save/saveas") at certain point, you could handle DocumentLockModeChanged event, where you test what command is causing that event (you test if the command is "qsave/save/saveas"), if yes, you can veto the command. Once you do not need to block it any more, simply remove the event handler. You may want to provide some kind of hint to the users when the saving command is vetoed, so that users would not be scared to think AutoCAD is broken (e.g. suddenly the saving command is not working!).

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

drobertsY4GL3
Enthusiast
Enthusiast

Thank you. That worked perfectly.

 

The use case is to temporarily color code any object in the drawing selected by the user and given a user assigned custom status. When the app window is closed, all the drawing objects shall revert to their normal colors. When the app is opened, it shall restore the saved status colors for the drawing, etc.

 

As I understand, this can also be done via overrules but it has proven to be much more difficult to implement properly on a per selected object(s) bases, especially when the selection may include multi-level blocks, leaders, or dimensions. I have opted to simply change the color properties of the objects instead, and revert the colors back to their stored original values on app close.

 

Saving of the drawing can be disabled, as the app saves it's own content in an external database.

Below is the code that worked for me based on your suggestion.

 

 

 

 

private List<string> commandsToVeto = new List<string>() { "QSAVE", "SAVE", "SAVEAS", "SAVEALL" };
 documentManager.DocumentLockModeChanged += DocumentManager_DocumentLockModeChanged;
// Disable saving while app is running in order to protect the user from accidentally
// saving temporary working colors to the drawing file.
        private void DocumentManager_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
        {         
            foreach(var command in commandsToVeto)
            {
                if (e.GlobalCommandName == command)
                {
                    e.Veto();
                    System.Windows.MessageBox.Show("Save is disabled while the model check app is running.\nPlease close the model check window to save.");
                }
            }
        }

 

 

 

 


Thanks again.

 

0 Likes