Fusion 360 Python Script - Get Top Level Folder Name

Fusion 360 Python Script - Get Top Level Folder Name

isocam
Collaborator Collaborator
508 Views
1 Reply
Message 1 of 2

Fusion 360 Python Script - Get Top Level Folder Name

isocam
Collaborator
Collaborator

Can anybody help?

 

I have created a project (folder), in Fusion 360, called "Purchased Parts".

 

Inside this "Purchased Parts" project (folder) I have created several sub-projects (folders) called "Bearings", "Fasteners", "Gearboxes" etc.

 

For testing purposes, I have inserted a part from the project (folder) called "Bearings" into a Fusion 360 assembly.

 

When I run the following code, I get the project (folder) name called "Bearings" displayed in a message box, however, I need to get the top level folder "Purchased Parts".

 

Does anybody know how I can change the following code so that I get the top level project?

 

Here is my code.

 

def traverseAssembly(occurrences, currentLevel):
app = adsk.core.Application.get()

ui = app.userInterface


for i in range(0, occurrences.count):
occ: adsk.fusion.Occurrence = occurrences.item(i)


doc: adsk.core.Document = occ.component.parentDesign.parentDocument

if doc.dataFile:
FolderName = doc.dataFile.parentFolder.name

ui.messageBox(FolderName, 'Fusion 360', 0, 3)

return FolderName

 

Therefore, the folder name should be "Purchased Parts" rather than "Bearings".

 

The line, coloured Red, needs changing.

 

Many thanks in advance!

 

Kindest regards

 

Darren

0 Likes
509 Views
1 Reply
Reply (1)
Message 2 of 2

BrianEkins
Mentor
Mentor

I think it needs to be:

FolderName = doc.dataFile.parentProject.name

The problem is that you're interchangeably using the terms "Project" and "Folder", but they're two distinct and different things. 

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