Python Script - Save To Specific Folder

Python Script - Save To Specific Folder

isocam
Collaborator Collaborator
772 Views
1 Reply
Message 1 of 2

Python Script - Save To Specific Folder

isocam
Collaborator
Collaborator

Can anybody help?

 

I have the following Python script file....

 

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

# get active document
doc :adsk.core.Document = app.activeDocument

# get data folder
dataProject :adsk.core.DataProject = app.data.dataProjects[0]
rootFolder :adsk.core.DataFolder = dataProject.rootFolder

# exec saveAs
doc.saveAs('hoge', rootFolder, '', '')

msg = f'You have saved the active document to\n'
msg += f' project "{dataProject.name}" with the name "{doc.name}".'
ui.messageBox(msg)

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

 

Please see the attached picture.

 

Then you run the script it saves a file called 'hoge' to the "Assets" LIBRARIES (Ringed In Blue).

 

Does anybody know how  to modify the script so that it saves a file called "hoge" to any of the folders in the

"Project Files" directory, for example "1040 - Darrens Test Folder" or "2000 - Cromar Platform - OLD" etc etc

 

Many thanks in advance!

 

Darren

 

 

0 Likes
Accepted solutions (1)
773 Views
1 Reply
Reply (1)
Message 2 of 2

BrianEkins
Mentor
Mentor
Accepted solution

Your problem is where you're getting the project to save into. You're getting the first project in the collection, which apparently happens to be the "Asset Libraries" folder. You either need to find the project based on the name or you can use the line below to use the project that is currently active in the data panel.

 

dataProject: adsk.core.DataProject = app.data.activeProject
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes