Getting a list of all (closed and open) documents in a project

Getting a list of all (closed and open) documents in a project

Anonymous
Not applicable
1,230 Views
2 Replies
Message 1 of 3

Getting a list of all (closed and open) documents in a project

Anonymous
Not applicable

Hello,

I would like to be able to access all the documents/designs from a project via the programming interface.

I don't want to be limited to open documents, therefore adsk.core.Application.get().documents does not work for me, since it only returns open documents.

So how do I get an array of all documents / designs / whatever in general or from a specific project?

I tried

  • adsk.core.DataProjects

  • adsk.core.DataHubs

but they appear to be emptyinaccessible structures to me. Even If I have opened a saved document. I've read the reference on all of the objects that I thought to be helpful. But I did not find a solution.

 

Just for context: the ultimate goal is to rehash the ParameterIO.py add-in to always be able to apply my external parameters to a whole project, without opening each file individually and clicking "import".

 

Thanks in advance, I appreciate your help.

0 Likes
1,231 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

The Data related functionality is what you can use to do what you want.  Below is a sample that finds a project with a certain name and then uses a recursive function to get every file in the project.  I'm generating a string with all of the data in this sample, but you could be building a list of the files and then operating on that list to do whatever you want with the files.  One word of warning is that any of the Data related functionality tends to be quite slow so be patient when you run it. 

 

 

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

' Find a specific project. project = adsk.core.DataProject.cast(None) for project in app.data.dataProjects: if project.name == 'Woodworking':
' Get the list of files in the project by starting with the root folder. results = '' results = getFiles(project.rootFolder, results, 0) file = open('c:/Temp/folderDump.text', 'w') file.write(results) file.close() ui.messageBox('Finished') return ui.messageBox('Project not found.') except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) ' Recursive function used to get all of the files in a specified folder. def getFiles(folder, results, depth): try: results += '\n' + (' ' * (depth * 4)) + folder.name
' Create the list of files. f = adsk.core.DataFolder.cast(folder) file = adsk.core.DataFile.cast(None) for file in f.dataFiles: results += '\n' + (' ' * ((depth+1) * 4)) + file.name
' Recursively call this function for any subfolders. for subFolder in f.dataFolders: results = getFiles(subFolder, results, depth+1)
' Return the current results. return results except: return False
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

Anonymous
Not applicable

Thank you for your answer Brian,

 

your solution takes 1-2 minutes to run on my computer and the UI is completely blocked in the mean time. This is not very practical.

Furthermore I should have emphasized it more clearly, that I have many subprojects per project and that I'm rather interested in having the list of files of one subproject as an actual array of DataFiles / Designs that I can manipulate rather than having the list of files.
But I'm positive that I can figure it out based on your code and I'll post it here when I'm done.

 

Edit: With only getting the files of one subproject the script runs in 15 seconds now instead of more than a minute

0 Likes