Fusion 360 Python Script Problem - Add Folder Name To Output

Fusion 360 Python Script Problem - Add Folder Name To Output

isocam
Collaborator Collaborator
435 Views
1 Reply
Message 1 of 2

Fusion 360 Python Script Problem - Add Folder Name To Output

isocam
Collaborator
Collaborator

Can anybody help???

 

Please see the attached ".txt" file (I have changed the file extension from .py to .txt)

 

I can run the script on an assembly document OK.

 

All I need to do is to add the document's folder name to the output file (shown in the script file as ??????????)

 

For example,

 

I have a main project file where all my documents (assemblies, parts & drawings are stored)

 

I also have two other folders "Purchased Parts" & "Referenced Parts". Please see the attached picture.

 

I need to update the script file to show the folder name where the document has been inserted into the assembly.

 

In the example, show above, this could be "Purchased Parts" & "Referenced Parts".

 

Can anybody update the script for me to allow me to add the folder name to the output?

 

Many thanks in advance!

 

Darren

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

Rushikesh.kadam
Autodesk
Autodesk

@isocam one can use DataFile.childReferences property to get a list of referenced designs. You can loop through the list to get the details like file name, folder name, project name etc.

Below is a sample script to output the details of external references in a file.

 

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


def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        document = design.parentDocument.dataFile
        info = "\n"
        for external_ref in document.childReferences:
            info += f'\n File name: {external_ref.name}'
            info += f'\n Folder name: {external_ref.parentFolder.name}'
            info += f'\n Project name: {external_ref.parentProject.name}'
            info += "\n-----------------------------------"
        app.log(info)

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

 

 

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

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.