Get project name at documentSaved event
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to get the name of a project from a document; the only way I can find to do that is through the dataFile of the document. However, when I read the info just after it is saved for the first time (using the documentSaved event) the dataFile is not yet available.
I feel like there my be a solution, like waiting for the file to be available, but I can't think of way to do something like that.
As far as I understand the file is saved locally, then the documentSaved event triggers and then the file is saved to A360 as a dataFile. I tried using a sleep() timer to check if it was available after a while but all it did was delay the creation of the dataFile.
Is there anyone who can think of a better solution to this situation?
This is what I've got:
import adsk.core, adsk.fusion, traceback
_handlers = []
def run(context):
ui = None
try:
app = adsk.core.Application.get()
onDocumentSaved = runAfterSave()
app.documentSaved.add(onDocumentSaved)
_handlers.append(onDocumentSaved)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler for the documentSaved event.
class runAfterSave(adsk.core.DocumentEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.activeDocument
data = doc.dataFile #!
project = data.parentProject
ui.messageBox(project.name)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))