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: 

folder.uploadFile conflicts with progressDialog

0 REPLIES 0
Reply
Message 1 of 1
MortenGuldager
159 Views, 0 Replies

folder.uploadFile conflicts with progressDialog

I am writing a script to upload multiple files so an progress indicator is in order. I seems fileUpload conflicts with progressDialog

The following should demonstrate how the program get stuck after the first file. It continues is cancel gets hit a few times. 

Program is expected to create test-project and 5 similar files within. You will need to adjust fn to point to your file if trying for yourself.

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


def uploadfile(folder, filename):
    future = folder.uploadFile(filename)
        
    while True:
        if future.uploadState == adsk.core.UploadStates.UploadFinished:
            return
            
        elif future.uploadState == adsk.core.UploadStates.UploadFailed:
            raise Exception("upload failed")
            
        adsk.doEvents()
        time.sleep(0.1)


def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
       
        ui.messageBox("begin")
        max = 5

        progressDialog = ui.createProgressDialog()
        progressDialog.cancelButtonText = 'Cancel'
        progressDialog.isBackgroundTranslucent = False
        progressDialog.show("Scanning", "loop %v of %m", 0, max)
        
        project = app.data.dataProjects.add("test-project")
        folder = project.rootFolder
        
        fn = "C:/Users/mogul/Desktop/test.f3d"
        for _ in range(max):
            uploadfile(folder, fn)
            progressDialog.progressValue += 1
            adsk.doEvents()
            time.sleep(1)

        ui.messageBox("done")


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

 Any obvious mistakes in the code above or have I just stumbled across a bug in the API? 

0 REPLIES 0

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