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

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

4 REPLIES 4
Reply
Message 1 of 5
isocam
575 Views, 4 Replies

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

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

 

Tags (1)
4 REPLIES 4
Message 2 of 5
HughesTooling
in reply to: isocam

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


Message 3 of 5
isocam
in reply to: isocam

Hi,

 

I need to only save "f3d" files only.

 

Many thanks!

 

Darren

 

Message 4 of 5
HughesTooling
in reply to: isocam

@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
in reply to: isocam

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

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