DataFileFuture.uploadState is not updating when commandInputs are used in a plugin

DataFileFuture.uploadState is not updating when commandInputs are used in a plugin

sharas_s
Contributor Contributor
875 Views
6 Replies
Message 1 of 7

DataFileFuture.uploadState is not updating when commandInputs are used in a plugin

sharas_s
Contributor
Contributor

Hello everyone,

 

I am trying to make a simple script that uploads a template document multiple times into F360 for later use. Stumbled into a strange issue when commandInputs are involved. 
Attached example plugin (will appear under utilities/add-ins in F360) which should replicate the issue. 


Made 2 buttons in this plugin: "Upload example CommandInput" and "Upload example simple"


Simple version just takes predefined values and upload local document multiple times in sequence with no problems and works great.
But I want to be able to change which local document to upload and the quantity. And when I add CommandInput  for that (in "Upload example CommandInput" button), it seems something strange happens in F360 and DataFileFuture.uploadState does not change its value even if you wait for a while. This results in an infinite loop and requires killing F360 and restarting it.  After restart, documents that the plugin was uploading are fully uploaded and I am able to open them.


While investigating this issue I couldn't pinpoint the exact command which causes this issue but it seems CommandInput somehow is related. 
Maybe someone knows what could be the reason for this or is it a bug?

0 Likes
Accepted solutions (1)
876 Views
6 Replies
Replies (6)
Message 2 of 7

sharas_s
Contributor
Contributor

Maybe someone could have a look at this issue? @hanskellner @prainsberry 

0 Likes
Message 3 of 7

Rushikesh.kadam
Autodesk
Autodesk

@sharas_s In the latest Fusion release, I am able to change and upload the file to the required quantity. Tried with 5 quantities, and there was no problem with the upload.

Rushikeshkadam_0-1655463808897.png

 

 

Can you take the latest Fusion update and check if you are still facing the issue?

 

------------------------------------------------------------------------------------------------------------------------------

If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed.

 




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


Message 4 of 7

sharas_s
Contributor
Contributor

Hey @Rushikesh.kadam , thank you for taking a look into this issue and sorry for a late reply.

I updated F360 (current version 2.0.13377) but it still hangs when I try uploading with CommandInputs.
Attached video showing it. After it hangs, I kill F360 and relaunch it to show that the file was uploaded once

[video]

0 Likes
Message 5 of 7

Rushikesh.kadam
Autodesk
Autodesk

@sharas_s I am still not able to reproduce the case. Here is a recording of the steps I am following.

Can you help identify if anything I am missing?

 

Regards,




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


0 Likes
Message 6 of 7

sharas_s
Contributor
Contributor

It seems you did everything the same way I did. So maybe it is something specific to my PC, F360 setup. Any ideas what could help?
I tried clearing cache data but that didn't help

0 Likes
Message 7 of 7

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi @sharas_s ,

 

I had the same problem in my environment.  I'm running Fusion360's latest version "2.0.13377".

I made a change to check the status of the upload process not with the future flag, but instead with the dataFile.isComplete attribute. Other change I made was to send all files creations requests at once, and then make only one monitoring loop.  With this change both launchers (simple and commandInput) run successfully.

 

The conclusion I have is that the file status in the DataFileFuture.uploadState attribute is not updated, while the dataFile.isComplete attribute report the real status of the file.  

 

This is code with the modifications I made in upload.py:

def upload_file(folder, filepath):
    '''
    Use DataFileFuture to check upload state
    '''
    future = folder.uploadFile(filepath)

    adsk.doEvents()
    return future
    n = 0
    while True:
        n += 1
        futil.log(f'folder: {folder.name}, state: {future.uploadState}, valid: {future.isValid} - {n}')

        if future.uploadState == adsk.core.UploadStates.UploadFinished:
            return
            
        elif future.uploadState == adsk.core.UploadStates.UploadFailed:
            raise Exception("upload failed")
            
        adsk.doEvents()

def templates(template, quantity=1):
    app = adsk.core.Application.get()
    folder = app.data.activeProject.rootFolder

    name_template = 'blank'

    regex = re.compile( r'v\d+' )  # regex to find version number in filename
    template_version = regex.findall( template )[ 0 ]

    template_filepath = os.path.join( config.TEMPLATE_FOLDER, template ).replace( "\\", "/" ) 
    futureDict = {}
    folderDict = {}

    folder_idx = 1
    for _ in range(quantity):
        # find unused indexes
        used_folder_names = [ doc.name for doc in folder.dataFolders]
        while f'{name_template}_{folder_idx}' in used_folder_names:
            folder_idx += 1

        # create folder for template
        blank_name = f'{name_template}_{folder_idx}'
        blank_folder = folder.dataFolders.add(
            f"{blank_name}"
        )
        adsk.doEvents()

        
        left_blank_folder = blank_folder.dataFolders.add(
            f"Left_{template_version}"
        )
        adsk.doEvents()

        right_blank_folder = blank_folder.dataFolders.add(
            f"Right_{template_version}"
        )
        adsk.doEvents()

        # start uploading template
        # Option 1
        k = f'L{_}'
        futureDict[k] = upload_file( left_blank_folder, template_filepath)
        folderDict[k] = left_blank_folder
        v = folderDict[k]

        k = f'R{_}'
        futureDict[k] = upload_file( right_blank_folder, template_filepath)
        folderDict[k] = right_blank_folder
        v = folderDict[k]

    n = 0
    while True:
        adsk.doEvents()
        succ = 0
        fail = 0
        comp = 0
        status = ''
        n += 1
        for k,v in futureDict.items():
            r = v.uploadState
            if r == adsk.core.UploadStates.UploadFinished:
                succ += 1
            elif r == adsk.core.UploadStates.UploadFailed:
                fail += 1
            df = adsk.core.DataFolder.cast(folderDict[k])
            if df and df.dataFiles and df.dataFiles.count and df.dataFiles.item(0):
                if df.dataFiles.item(0).isComplete:
                    x = 'T'
                    comp += 1
                else:
                    x = 'F'
            else:
                x = ' '
            status += f'{k} {r}{x[0]}  '
        futil.log(f'{status} {comp} {n}')
        if succ + fail == quantity * 2 or comp == quantity * 2:
            return

 

Take a look at the output messages where I print the status of each file it finds in the waiting loop:

Captura de pantalla 2022-07-12 105729.png

In yellow the files ID, in orange the future attribute and in green the dataFile.isComplete attribute.

Notice all orange equal to 0 (UploadProcessing) while the greens vary on each iteration.

First run was made with commandInput while second was made with simple script.

 

I hope this could help support team to check why the inconsistency in the two attributes is happening.

Let me know if it works for you on your environment.

 

Regards,

Jorge