Reply
Explorer
10 Posts
1 Kudo

How to save as DXF programmatically

45 Views, 3 Replies
2 weeks ago

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.")

Autodesk Support
1259 Posts
353 Kudos
369 Solutions

Re: How to save as DXF programmatically

2 weeks ago in reply to: jmperez6

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.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Explorer
10 Posts
1 Kudo

Re: How to save as DXF programmatically

2 weeks ago in reply to: ekinsb

Ok, but how do you save a sketch or project programmatically? doesn't matter what format, I just want to save it programmatically.

Highlighted
Autodesk Support
1259 Posts
353 Kudos
369 Solutions

Re: How to save as DXF programmatically

2 weeks ago in reply to: jmperez6

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()))

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog