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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create folder structure

Message 1 of 7
1291 Views, 6 Replies

Create folder structure

Hi, I need to recreate a local folder structure in a project within Fusion 360.


I can read the local folders, I can create folders within Fusion 360 but I can't create sub folders to recreate the structure.


Local folders ..


  • Root Folder
    • Folder One
      • Sub Folder One
      • Sub Folder Two
    • Folder Two
      • Sub Folder One
    • Folder Three


Could someone help me with this?


Thanks !

Message 2 of 7
in reply to: michelmarroche



You can create a project folder structure like that with something like this:

project =
root = project.rootFolder
folders = root.dataFolders
folderOne = folders.add('Folder One')
folderTwo = folders.add('Folder Two')
folderThree = folders.add('Folder Three')
folders = folderOne.dataFolders
oneSubOne = folders.add('Sub Folder One')
oneSubTwo = folders.add('Sub Folder Two')
folders = folderTwo.dataFolders
twoSubOne = folders.add('Sub Folder One')



Kris Kaplan
Message 3 of 7
in reply to: KrisKaplan

Hi! thanks .. the explanation is very clear .. I have managed to put together a function to recreate the folders and it works .. but I cannot work on the basis of existing folders ..


For example, if I had already created the structure that you propose and wanted to create a sub-folder in one of them ... how would you do?

Message 4 of 7
in reply to: michelmarroche

You would do that in pretty much the same way as you create the folder structure. You need to traverse the structure down to the DataFolder that you wish to create a sub folder in, and use the same 'folder.dataFolders.add(...)' method.


So the question might be how to find the parent folder of the new sub folder you wish to create. I assume you have a path (array) of folder names. So from the root folder you could get the next level dataFolders collection, and use the itemByName method to find the next level. Do this for each folder in the path until you get to the leaf/parent folder in your path.



Kris Kaplan
Message 5 of 7
in reply to: KrisKaplan

Sorry I explain a little what I'm doing ..

Like many others, the change in Fusion 360 policies affected me. I tried to buy a commercial account for the user who already had an educational account but they told me it was not possible, so I bought a commercial license with another email. .

I tried to use some scripts to back up the information from the cloud locally but since I couldn't do it with the details that I needed, I created one and with it I was able to download all my files, the details of it are that I lower them by project, that I can maintain the structure of folders locally and that when I have image files, pdf, or drawings, I create a reference file to later download and place them in their original project.

Now that I have everything backed up locally, I want to recreate all this in the cloud, but I want to do it through a script so that everything is automated and maybe it can serve other users in the same situation.


I can already read the local structure, but now I need to replicate that structure in the cloud, and for this I need to be able to define a function that says I want to create a folder in the folder .. one / two / three .. and then be able to load in folders and subfolders ..


The loading functions work, creating folders too, etc ... but I am missing the detail of being able to say by it ... create a folder called four in one / two / three / ... I mean?


Thanks again and I hope this can generate a useful application .. we have a few days left so that many can quickly support their projects

Message 6 of 7
in reply to: michelmarroche

@michelmarroche wrote:

...create a folder called four in one / two / three / ...

I think this was the question I was trying to answer. What you need to do is find the folder named 'three' and create the 'four' folder in its dataFolders collection. And to find 'three', you need to start at the root folder (for the desired project), and get 'one' from it, then get 'two' from 'one', then get 'three' from 'two'. In code it would be something like:


def createSubFolder(parentFolder: adsk.core.DataFolder, name: str) -> adsk.core.DataFolder:
	return parentFolder and parentFolder.dataFolders.add(name) or None

def getFolder(parentFolder: adsk.core.DataFolder, name: str, create = True) -> adsk.core.DataFolder:
	folders = parentFolder and parentFolder.dataFolders
	folder = folders and folders.itemByName(name)
	folder = folder or create and createSubFolder(parentFolder, name) or None
def getFolderFromPath(path, project: adsk.core.DataProject, create = True) -> adsk.core.DataFolder:
	folder = project.rootFolder
	for name in path:
		folder = getFolder(folder, name, create)

def main():
	project = adsk.core.Application.get().data.activeProject
	parentFolder = getFolderFromPath(('one', 'two', 'three'), project)
	newFolder = createSubFolder(parentFolder, 'four')



Kris Kaplan
Message 7 of 7
in reply to: KrisKaplan

Hi ! thank you ! your guide was very useful ..


Now I will have to solve some small details but it is already working.


The idea is to upload a complete structure of folders and subfolders with their corresponding files to their corresponding projects.


Thank you very much again!

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