folder.uploadFile conflicts with progressDialog

folder.uploadFile conflicts with progressDialog

MortenGuldager
Participant Participant
310 Views
0 Replies
Message 1 of 1

folder.uploadFile conflicts with progressDialog

MortenGuldager
Participant
Participant

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 Likes
311 Views
0 Replies
Replies (0)