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.
Solved! Go to Solution.
Solved by BrianEkins. Go to Solution.
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)
Can't find what you're looking for? Ask the community or share your knowledge.