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: 

How to save as DXF programmatically

4 REPLIES 4
Reply
Message 1 of 5
jmperez6
438 Views, 4 Replies

How to save as DXF programmatically

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

4 REPLIES 4
Message 2 of 5
ekinsb
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
Message 3 of 5
jmperez6
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.

Message 4 of 5
ekinsb
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
Message 5 of 5
pludikar
in reply to: ekinsb

@ekinsb 

 

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

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).

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