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: 

Save Sketch To DWG File Using A Python Script

1 REPLY 1
SOLVED
Reply
Message 1 of 2
isocam
189 Views, 1 Reply

Save Sketch To DWG File Using A Python Script

Can anybody help???

 

I have created a simple sketch, for testing purposes, and extruded it.

 

The sketch will always be called "Sketch1" consisting of Lines, Arcs and Circles.

 

I want to be able to automatically save the sketch as a 2D AutoCAD "Dwg" file, when I run a Python script.

 

I do not want to manually select the sketch first as the sketch will always be called "Sketch1".

 

Can this be done?

 

Many thanks in advance!

 

Darren

1 REPLY 1
Message 2 of 2
kandennti
in reply to: isocam

Hi @isocam .

 

You cannot export a sketch as a DWG file.
It is the same with the GUI.

 

Here is a sample of exporting as a DXF file instead.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-a627026a-27c7-4430-b38a-e51564a4a640 

# Fusion360API Python script
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
        des :adsk.fusion.Design = app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        skt = root.sketches.itemByName('Sketch1')
        if not skt:
            return

        exportDXF_Desktop(skt, 'hoge.dxf')


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


def exportDXF_Desktop(
    skt: adsk.fusion.Sketch,
    filename: str, 
    ):

    import os
    desktop_dir = os.path.expanduser('~/Desktop')

    import pathlib
    path = pathlib.Path(desktop_dir, filename)

    skt.saveAsDXF(str(path))

 

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