Save Dxf file Automatically

Save Dxf file Automatically

isocam
Collaborator Collaborator
447 Views
1 Reply
Message 1 of 2

Save Dxf file Automatically

isocam
Collaborator
Collaborator

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

0 Likes
448 Views
1 Reply
Reply (1)
Message 2 of 2

erik
Advocate
Advocate

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