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: 

Save "Project Folder" names to an ascii text files

1 REPLY 1
SOLVED
Reply
Message 1 of 2
isocam
120 Views, 1 Reply

Save "Project Folder" names to an ascii text files

Can Anybody help?

 

Is it possible to save all the folder names, contained in the "Projects Folder" only to a asci text file?

 

Please see the attached picture for an example of the folder structure.

 

So that the text file would be something like.....

 

0101 - Darrens Test Folder

1000 - Silo Foot

1005 - Sand Silo Leg

1010 - Silo Fill Bend

etc

etc

 

Many thanks in advance!!

 

Darren

1 REPLY 1
Message 2 of 2
BrianEkins
in reply to: isocam

Here's a little script that will do it. Remember that folders can contain other folders to any depth. This script recursively traverses the entire folder structure and will indent for each level.

 

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

        folders = ''
        result = getFolders(project.rootFolder, folders, 0)

        with open('C:\Temp\FolderList.txt', 'w') as f:
            f.write(result)
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def getFolders(currentFolder: adsk.core.DataFolder, folderList: str, level: int) -> str:
    folder: adsk.core.DataFolder
    for folder in currentFolder.dataFolders.asArray():
        # Create spaces for the indent depending on the current level.
        spaces = ' ' * (level * 2)
        if folderList == '':
            # Add the name of the first folder.
            folderList = spaces + folder.name
        else:
            # Add the name of all other folders with a newline before it.
            folderList += '\n' + spaces + folder.name

        # Recursively call this function to get any child folders.
        folderList = getFolders(folder, folderList, level + 1)

    return folderList
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

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