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: 

Access file tree structure.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
LiveLover
800 Views, 6 Replies

Access file tree structure.

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

Thank you!

Labels (1)
6 REPLIES 6
Message 2 of 7

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 
 Sr. Quality Engineer in Fusion
Autodesk
LinkedIn
Message 3 of 7
JeromeBriot
in reply to: LiveLover

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

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

 

Message 5 of 7

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 
 Sr. Quality Engineer in Fusion
Autodesk
LinkedIn
Message 6 of 7
kandennti
in reply to: JeromeBriot

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
in reply to: kandennti


@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:

 

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

Post to forums  

Autodesk Design & Make Report