Stop document saving

Stop document saving

j.han97
Advocate Advocate
896 Views
5 Replies
Message 1 of 6

Stop document saving

j.han97
Advocate
Advocate

Hi all,

 

Due to security concern my team should not upload sensitive data to cloud storage. Therefore I wrote an add-in to monitor the Application.documentSaving event. According to the documentation, 

'You can set the isSaveCanceled property of DocumentEventArgs to true to cancel the document save.'

 

But when I test this add-in, the saving process is not interrupted at all. The problem is, there is no 'isSaveCanceled' property in both the documentation and the code hint in VSCode.

 

The sample add-in is posted below. Your help is highly appreciated!

 

#Author-
#Description-This add-in is used to disable upload/saving any file to Fusion 360 cloud server

import adsk.core, adsk.fusion, adsk.cam, traceback

class documentSavingEventHandler(adsk.core.DocumentEventHandler):
    def __init__(self):
        super().__init__()
    
    def notify(self, args):
        _app.log('Detected document saving')
        eventArgs = adsk.core.DocumentEventArgs.cast(args)
        #Tried with/without firingEvent
        ##eventArgs.firingEvent.isSaveCanceled = True
        eventArgs.isSaveCanceled = True
        

_app: adsk.core.Application = adsk.core.Application.get()
_ui: adsk.core.UserInterface = _app.userInterface
_handlers = []

def run(context):
    try:
        _app.log('Addin is running')
        onDocumentSaving = documentSavingEventHandler()
        _app.documentSaving.add(onDocumentSaving)
        _handlers.append(onDocumentSaving)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    try:
        _app.log('Stop addin')
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

0 Likes
Accepted solutions (1)
897 Views
5 Replies
Replies (5)
Message 2 of 6

kandennti
Mentor
Mentor

Hi @j.han97 .

 

I also tried several text commands, but I could not abort the save.

I think it's a bug.

0 Likes
Message 3 of 6

BrianEkins
Mentor
Mentor
Accepted solution

This is a case where a behavior was specified but either because of technical issues or because of time was not implemented and the specification, which becomes the documentation, was not updated to reflect the actual behavior.  There is a bug, but the bug is with the documentation.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 6

j.han97
Advocate
Advocate

Hi @BrianEkins ,

 

Thank you so much for your answer. Based on your knowledge on Fusion 360 API, is there any way to prevent files from being uploaded to cloud server? This is a major security concern (at least for my team) while dealing with sensitive information. (Not that we thought that Fusion 360's cloud server is unsafe, but the fact that the data will be outside of our control is already a serious risk to us)

 

In addition, you mentioned that the reason of not implementing this feature (property) is due to either technical/time limitations. Is it something on the working list of the development team so that we can expect it to be available soon in future versions of Fusion 360?

0 Likes
Message 5 of 6

kandennti
Mentor
Mentor

@j.han97 .

 

By using the commandStarting event, I was able to prevent the file from being saved in online mode.

# Fusion360API Python Addin
import adsk.core
import adsk.fusion
import traceback

_app: adsk.core.Application = adsk.core.Application.get()
_ui: adsk.core.UserInterface = _app.userInterface
_handlers = []

class MyCommandStartingHandler(adsk.core.ApplicationCommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args: adsk.core.ApplicationCommandEventArgs):

        if args.commandId != 'PLM360SaveCommand':
            return

        global _app, _ui
        if not _app.isOffLine:
            _ui.messageBox('Saving in online mode is stopped by the add-in.')
            args.isCanceled = True

def run(context):
    try:
        global _app, _ui, _handlers
        _app.log('Addin is running')

        onCommandStarting = MyCommandStartingHandler()
        _ui.commandStarting.add(onCommandStarting)
        _handlers.append(onCommandStarting)

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    try:
        global _app
        _app.log('Stop addin')
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 6 of 6

j.han97
Advocate
Advocate

Hi @kandennti,

 

This is a brilliant way I have never thought of! Thank you and I will test it out soon. 

0 Likes