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: 

Get a list of all the documents in the Recent Data folder

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
bevis.hobbs21
546 Views, 2 Replies

Get a list of all the documents in the Recent Data folder

How do you get a list of all the documents in the Recent Data folder using a python Add-In?

I tried to find a way of getting the time saved of all the documents and then from there I could find out which ones are in the recent data folder. But I couldn't find a way of doing this in the API.

This code gets all the saved documents:

all_documents = [file for project in app.data.dataProjects 
                 for file in project.rootFolder.dataFiles]

But I'm not sure how to get the time saved for each document.

 

Labels (1)
2 REPLIES 2
Message 2 of 3
BrianEkins
in reply to: bevis.hobbs21

Here's some code that I believe will do it.  I didn't test it with a lot of projects or files but it seemed to work on my smaller dataset.

 

Because you can have folders many levels deep, it uses a recursive function to get all of the folders.  It gets every file and then sorts them based on the date of the latest version.

 

from datetime import datetime

def sortFunc(fileData):
    return fileData['date']

def GetFileListByDate(): 
    app = adsk.core.Application.get()
    files = []    
    for project in app.data.dataProjects:
        recurseFolders(project.rootFolder, files)

    files.sort(key=sortFunc, reverse=True) 
    for file in files:
        print('{} - {} - {}'.format(file['file'], file['project'], datetime.utcfromtimestamp(file['date']).strftime('%Y/%m/%d %H:%M:%S')))


def recurseFolders(folder, files):
    # Get the files in this folder:
    for file in folder.dataFiles:
        if file.fileExtension == 'f3d' or file.fileExtension == 'f3z':
            lastFile = file.latestVersion
            files.append({'file': file.name, 'project': file.parentProject.name, 'date': file.dateCreated})

    # Iterate over the folders in this folder.
    for subFolder in folder.dataFolders:
        recurseFolders(subFolder, files)
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3
bevis.hobbs21
in reply to: BrianEkins

Thanks that's exactly what I wanted.

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

Post to forums  

Autodesk Design & Make Report