Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Blocking Call to Document.save[As]

1 REPLY 1
Reply
Message 1 of 2
scruffmeister
138 Views, 1 Reply

Blocking Call to Document.save[As]

Hi,


The API supports a callback that is called when a data file upload has completed including any cloud side translation, which is demonstrated by the Save and Insert File API Sample.

 

However, there are situations in my script where I just need to wait until the save is complete and can't continue until it is, e.g.

 

 

doc.save("new version")
# WAIT UNTIL SAVE COMPLETES
nextFunction()

 

 

 

Is there a way to do this with the API, for example by receiving a "future" object representing the result of the save, that can be waited on with future.result(timeout)? I note that the DataFolder and Component classes seems to support a DataFileFuture, but for some reason the Document.save[As] mechanism doesn't?

 

Will this functionality be coming to the API/or is there an example of how I can achieve what I am asking? I know it is less efficient, but in my use-case async programming just complicates my script which is essentially just automation of a human workflow.

 

Thank you!

1 REPLY 1
Message 2 of 2
BrianEkins
in reply to: scruffmeister

It's not ideal, but you can do something like the code below. The starts a loop where adsk.doEvents() is called. The API and the Fusion UI run in the same thread, so while the API is running, the Fusion UI is blocked. The doEvents function returns control over to Fusion so any pending messages can be processed and then control returns back to the API. The logic to end the loop in this is checking to see if a new version of this document is available. It would be wise to add something else, like a timeout, in case the save isn't able to complete and a new version never becomes available.

 

 

curVersion = doc.dataFile.latestVersionNumber
doc.save("new version")
while doc.dataFile.latestVersionNumber == curVersion:
    adsk.doEvents()

nextFunction()

 

 

I agree that async programming is a pain, but comes into play anytime Fusion is interacting with its cloud side.

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report