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 Dxf file Automatically

1 REPLY 1
Reply
Message 1 of 2
isocam
250 Views, 1 Reply

Save Dxf file Automatically

Can anybody help???

 

I have the following script file:

 

import adsk.core, adsk.fusion, traceback

import os

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()

        ui = app.userInterface

        sketches = []

        for seln in ui.activeSelections:
            sketch = adsk.fusion.Sketch.cast(seln.entity)

            if sketch:
                sketches.append(sketch)

            for sketch in sketches:
                fullpath = os.path.join('C:\Pda', sketch.name)

                ui.messageBox(fullpath)

                sketch.saveAsDXF(fullpath + '.dxf')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

When I run it, I need to firstly, manually select the sketch.

 

Is there any way that the above script can be modified so that "Sketch1" is always automatically selected without me having to manually select it first???

 

Many thanks in advance!!!!!

 

Darren

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

If you know in what component the sketch is located and the name of the sketch you can use the following code to get the sketch.

 

import adsk.core, adsk.fusion, traceback
import os

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct

        rootComp = design.rootComponent
        sketch = rootComp.sketches.itemByName("SketchName")

        fullpath = os.path.join('C:\Pda', sketch.name)
        ui.messageBox(fullpath)
        sketch.saveAsDXF(fullpath + '.dxf')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

The code will retrieve a sketch named: SketchName located in the root component.

 

If you have any further questions or this didn't solve the issue please write again.

 

- Erik

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