Access file tree structure.

Access file tree structure.

LiveLover
Advocate Advocate
1,677 Views
6 Replies
Message 1 of 7

Access file tree structure.

LiveLover
Advocate
Advocate

Hello! 
Can we observe projects list and project's directory/file structure?

Thank you!

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

sasikanth.kollipara
Autodesk
Autodesk

Hi, Thanks for using Fusion. Are you looking for API or a place to view the structure? 

 

You can see it in the web interface as well.

 

If my post answers your question, please click the "Accept Solution" button. This helps everyone find answers more quickly!

 

Regards,

Sas

 

 

 



Sasikanth Kollipara
Product owner and customer support in Fusion
Autodesk
LinkedIn
Message 3 of 7

JeromeBriot
Mentor
Mentor
Accepted solution

Hello,

 

Here is a script that list all hubs, projects, folders and files.

Note that the code takes time to end because it gets the information from the Autodesk server.

 

import adsk.core, adsk.fusion, traceback
import platform
import os

if platform.system() == 'Windows':
    desktopPath = os.path.join(os.getenv('USERPROFILE'), 'Desktop')
else:
    desktopPath = os.path.join(os.path.expanduser('~'), 'Desktop')

txtFile = os.path.join(desktopPath, 'DataFusion360.txt')


def getFolderData(folder, level, f):

    for dataFile in folder.dataFiles:
        f.write('\n' + '\t'*level + dataFile.name + ' | ' + dataFile.id)
    for dataFolder in folder.dataFolders:
        f.write('\n' + '\t'*level + dataFolder.name + ' | ' + dataFolder.id)
        getFolderData(dataFolder, level+1, f)


def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        with open(txtFile, 'w') as f:
            for dataHub in app.data.dataHubs:
                f.write(dataHub.name)
                for dataProject in dataHub.dataProjects:
                    f.write('\n\t' + dataProject.name + ' | ' + dataProject.id)
                    getFolderData(dataProject.rootFolder, 2, f)
                f.write('\n')

        ui.messageBox('End')

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

 

Message 4 of 7

LiveLover
Advocate
Advocate

Hello @sasikanth.kollipara! Thank you for replying!
https://www.autodesk.com/products/fusion-360/collaborator 
shows me 

LiveLover_0-1623225310139.png

 

is this because I have no some (what?) subscription?

And "ViewDetails on Web" brings me to a web observer for my projects

LiveLover_1-1623225447537.png

 

0 Likes
Message 5 of 7

sasikanth.kollipara
Autodesk
Autodesk
Accepted solution

You can click Access now on the above screenshot you shared and you should be able to view the web interface. 

 

And if you have the proper entitlement in Fusion, you are free to use this web interface for all your data management activities.  You can do File operations pretty easy along with the review capabilities. 

 

If my post answers your question, please click the "Accept Solution" button. This helps everyone find answers more quickly!

 

Regards,

Sas



Sasikanth Kollipara
Product owner and customer support in Fusion
Autodesk
LinkedIn
0 Likes
Message 6 of 7

kandennti
Mentor
Mentor

Hi @JeromeBriot .

 

I have made a similar script, but I did not do such detailed information. It's great.

 

It seems to be slightly faster to use the asArray method.
However, empty folders, etc. caused an error.

 

Also, I am using it in a Japanese environment, and due to encoding problems, I get an error when writing the file. If you are not an English-speaking user, you may experience the same error.
So, I decode the file before writing it out.

# Fusion360API Python script
import adsk.core, adsk.fusion, traceback
import platform
import os
import time

if platform.system() == 'Windows':
    desktopPath = os.path.join(os.getenv('USERPROFILE'), 'Desktop')
else:
    desktopPath = os.path.join(os.path.expanduser('~'), 'Desktop')

txtFile = os.path.join(desktopPath, 'DataFusion360.txt')

def getFolderData(folder, level, lst):
    try:
        for dataFile in folder.dataFiles.asArray():
            lst.append('\t'*level + dataFile.name + ' | ' + dataFile.id)
    except:
        pass

    try:
        for dataFolder in folder.dataFolders.asArray():
            lst.append('\t'*level + dataFolder.name + ' | ' + dataFolder.id)
            lst = getFolderData(dataFolder, level+1, lst)
    except:
        pass

    return lst

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        t = time.time()

        # get data
        lst =[]
        for dataHub in app.data.dataHubs.asArray():
            lst.append(dataHub.name)
            try:
                for dataProject in dataHub.dataProjects.asArray():
                    lst.append('\t' + dataProject.name + ' | ' + dataProject.id)
                    lst = getFolderData(dataProject.rootFolder, 2, lst)
            except:
                pass

        # write file
        with open(txtFile, 'w') as f:
            f.write(toDecode('\n'.join(lst)))

        ui.messageBox(f'Done:{time.time()-t}s')

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

def toDecode(s):
     return s.encode("CP932", "ignore").decode("CP932")

 

It is now faster than before, but access to the data hub is still slow.

Message 7 of 7

JeromeBriot
Mentor
Mentor

@kandennti  a écrit :

Also, I am using it in a Japanese environment, and due to encoding problems, I get an error when writing the file. If you are not an English-speaking user, you may experience the same error.
So, I decode the file before writing it out.


You can also try this :

 

with open(txtFile, 'w', encoding='cp932') as f: