Accessing save/version's description string from onDocumentSaving

Accessing save/version's description string from onDocumentSaving

ltomuta
Advisor Advisor
100 Views
2 Replies
Message 1 of 3

Accessing save/version's description string from onDocumentSaving

ltomuta
Advisor
Advisor

Looks like the description parameter given to document's save method cannot be accessed when handling the onDocumentSaving event.

It would be nice to be able to decide whether to allow or not to save based on the content of that string or to be able to change it before the save

0 Likes
101 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

Hi @ltomuta -san.

 

I tried it on the documentSaved event.
The description you can get is one of the previous ones.
The server is probably getting the Datafile before the upload is complete.

# Fusion360 python Addins
import traceback
import adsk.core as core
import adsk.fusion as fusion

_app: core.Application = core.Application.get()
_handlers = []

class MyDocumentSavedHandler(core.DocumentEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args: core.DocumentEventArgs):
        doc: fusion.FusionDocument = args.document
        datafile: core.DataFile = doc.dataFile

        # One previous description
        _app.log(f"description: {datafile.description}")


def run(context):
    try:
        onDocumentSaved = MyDocumentSavedHandler()
        _app.documentSaved.add(onDocumentSaved)
        _handlers.append(onDocumentSaved)

    except:
        _app.log('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 3 of 3

ltomuta
Advisor
Advisor

Yes, accessing the already saved strings is possible. But not the about to be saved string.

0 Likes