Python Script: Find Folders In Root Directory

Python Script: Find Folders In Root Directory

isocam
Collaborator Collaborator
499 Views
1 Reply
Message 1 of 2

Python Script: Find Folders In Root Directory

isocam
Collaborator
Collaborator

Can anybody help?

 

I have the following code. in a Fusion 360 Python script:

 

def ExportBomFile(BomFileName):
ui = None
try:
app = adsk.core.Application.get()

ui = app.userInterface

design = adsk.fusion.Design.cast(app.activeProduct)

activeDocumentName = design.parentDocument.dataFile.name

component: adsk.fusion.Component

for idx, component in enumerate(list(design.allComponents)):


ParentFolderName = str(dataFileFullPath(component.parentDesign.parentDocument.dataFile))

FolderName = component.parentDesign.parentDocument.dataFile.parentFolder.name

 

Can anybody update the above script so that it includes folders that are located in the root directory as well?

 

Please see the attached picture.

 

Many thanks in advance!!

 

Darren

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

Rushikesh.kadam
Autodesk
Autodesk

@isocam I may have not fully understood the requirement. But, here is a sample script that gets all the folders present under the root project of a file. From the DataProject object of a file, one can get the rootFolder(DataFolder object). This DataFolder has dataFolders property which is a list of all the folders present under it.

import  adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui  = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        for folder in design.parentDocument.dataFile.parentProject.rootFolder.dataFolders:
            app.log(folder.name)


        

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

The script considers only one level of folders. You will need to loop to consider subfolders.

 

Hope it helps,

------------------------------------------------------------------------------------------------------------------------------

If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.