Use a Fusion 360 Python script to use "SaveAs" to save a part to a specific folder

Use a Fusion 360 Python script to use "SaveAs" to save a part to a specific folder

isocam
Collaborator Collaborator
1,786 Views
4 Replies
Message 1 of 5

Use a Fusion 360 Python script to use "SaveAs" to save a part to a specific folder

isocam
Collaborator
Collaborator

Support,

 

Can anybody update the following script to allow me to use "SaveAs" to save a part to a specific folder?

 

import adsk.core, adsk.fusion, traceback

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

ui = app.userInterface

doc :adsk.core.Document = app.activeDocument

dataProject :adsk.core.DataProject = app.data.dataProjects[0]

rootFolder :adsk.core.DataFolder = dataProject.rootFolder

PartFileName = "TEST-FILE"

doc.saveAs(PartFileName, rootFolder, '', '')

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

 

 

I NEED TO USE SAVEAS TO SAVE A "TEST-FILE" TO THE FOLDER

Project Files > Projects > 1070 - Drive Shaft


I want, for test purposes, to use SaveAs to save a part to a folder called:

 

"Project Files" > "Projects" > "1070 - Drive Shaft"

 

Please see the attached picture.

 

Many thanks in advance!!

 

Darren

 

0 Likes
1,787 Views
4 Replies
Replies (4)
Message 2 of 5

HughesTooling
Consultant
Consultant

Sorry about previous answer, didn't realise you want to save to your hub.

 

You need to look at Component, not Document for this.

 

See this page in the help for SaveCopyAs from a component.

 

Mark

Mark Hughes
Owner, Hughes Tooling
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


0 Likes
Message 3 of 5

isocam
Collaborator
Collaborator

Hi,

 

I need to only save "f3d" files only.

 

Many thanks!

 

Darren

 

0 Likes
Message 4 of 5

HughesTooling
Consultant
Consultant

@isocam  I edited my previous answer. I didn't realise you wanted to save to your hub and not your local file system.

 

Mark

Mark Hughes
Owner, Hughes Tooling
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Message 5 of 5

BrianEkins
Mentor
Mentor

I was confused at first about what you're trying to do because your picture is a little confusing because of the names you've used for folders.  I believe you have a project named "Project Files" and then a folder within that project named "Projects" and it contains several folders including "1070 - Drive Shaft".  Assuming that's true and I haven't misunderstood what I saw, here's a little script that will the current document into the "1070 - Drive Shaft" folder, and the new file will be named "Test Part".  There's no error handling in case the project or a folder isn't found.  Because I don't have the same structure set up in my hub I wasn't able to test it but I believe it should work.

 

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

        data = app.data
        activeHub = data.activeHub

        # Get the project named "Project Files".
        proj: adsk.core.DataProject
        projFilesProject: adsk.core.DataProject = None
        for proj in activeHub.dataProjects:
            if proj.name == 'Project Files':
                projFilesProject = proj
                break

        # Get the folder named "Projects".
        projFolder = projFilesProject.rootFolder.dataFolders.itemByName('Projects')

        # Get the subfolder named "1070 - Drive Shaft".
        folder1070 = projFolder.dataFolders.itemByName('1070 - Drive Shaft')

        # Save As the active document.
        app.activeDocument.saveAs('Test Part', folder1070, 'Description', 'Tag')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

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