Hello, I'm writing an addin script and wanted to know how do you programmatically save files and how to save them as a DXF file.
I have this code so far, but it keeps giving me an error, about how the 2nd parameter "datafolder" is incorrect.
app = adsk.core.Application.get()
docu = app.activeDocument
datafolder = adsk.core.DataFolder
ui.messageBox("The name of the datafolder is: "+str(datafolder.name))
saved = docu.saveAs("FilecreatedFromGUI", datafolder, "Newly created file", "")
if(saved == True):
ui.messageBox("File was successfully saved!!!")
if(saved == False):
ui.messageBox("File failed to save.")
Unfortunately, the API does not currently support exporting a sketch as DXF. It's something we need to add support for in the future. Sorry about that.
Ok, but how do you save a sketch or project programmatically? doesn't matter what format, I just want to save it programmatically.
Here's some code that performs a Save As operation on the currently open document and creates the new file in the same folder as the active document. With a "Save As" operation, the currently open document becomes the document you just saved. Fusion doesn't support a "Save Copy As" where a copy is made and it leaves the active document alone. One of the arguments to the SaveAs is the folder to save to. For convenience I'm using the same folder as the active document but it's possible to use the API to find any other folder and save it to that instead.
def run(context): try: app = adsk.core.Application.get() ui = app.userInterface doc = app.activeDocument if not doc.isSaved: ui.messageBox('The document must be saved first.') return # Get the folder that the current document is saved in. folder = doc.dataFile.parentFolder # Perform a save as of the current document to the same folder. doc.saveAs('Save As Test', folder, 'Test of the Save As through the API', '') except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Is it still the case that saveAsDXF isn't supported under the API - even though there's been a method under sketch since Aug 2014 (according to the API reference pages)?
Peter