Automating or accelerating DXF export

Automating or accelerating DXF export

3d_low
Enthusiast Enthusiast
1,303 Views
6 Replies
Message 1 of 7

Automating or accelerating DXF export

3d_low
Enthusiast
Enthusiast

Hello there forum,

 

I do a lot of Sheetmetal in fusion and i was wondering if there is a way to accelerate the export of DXF files out of fusion. I've attached a screenshot of a typical assembly i have to export.

 

Most of the thing is automated (via parameters and pre-made drawings) but the DXF export is what consumes the most time. I'm trying to avoid moving to inventor because of multiple reasons.

 

Any work around? Anyone willing/able to tackle this?

 

Screenshot 2022-08-01 115004.png

 

 

0 Likes
1,304 Views
6 Replies
Replies (6)
Message 2 of 7

Jorge_Jaramillo
Collaborator
Collaborator

Hi @3d_low,

 

Just to clarify:

In your design, you have a sketch per each part?

It's what take you the time going sketch by sketch to export to a DXF file?

Do you expect a single DXF with all of the parts or multiple files, one per part in your design?

 

Regards,

Jorge

0 Likes
Message 3 of 7

3d_low
Enthusiast
Enthusiast

I'm expecting a dxf per part.

 

I create a flat pattern for each part that I update then export. I'm trying to have this done automatically.

Something that will save the DXF with the part name in the right folder

 

I'm using the DataPro extension to export my tubes that are going to laser cutting (i select all of them and export to STEP in a folder). I'm also using Find and Replace to rename all the components (each parts will start with 000x-PARTNAME, the plugin will replace the 000x with the part number)

 

The onyl thing missing is the DXF for the sheet metal laser.

Message 4 of 7

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

You can try this script:

import adsk.core, adsk.fusion, adsk.cam, traceback

DIRECTORY = 'c:/tmp/' # keep the / at the end

def exportSketches2DXF():
    app = adsk.core.Application.get()
    try:
        sks: adsk.fusion.Sketches = app.activeProduct.rootComponent.sketches
        for i in range(sks.count):
            filename = f'{DIRECTORY}{i:04d}-{sks.item(i).name}.dxf'
            sks.item(i).saveAsDXF(filename)
            app.log(f'{filename=} exported.')
        app.log(f'Exported DONE!')
    except:
        app.log('Failed:\n{}'.format(traceback.format_exc()))

def run(context):
    app = adsk.core.Application.get()
    ui = app.userInterface
    try:
        exportSketches2DXF()
    except:
        app.log('Failed:\n{}'.format(traceback.format_exc()))

 

Just set the value for DIRECTORY variable where you want the DXF files to be saved.

It will save each sketch (in the root component) in a file in the format <DIRECTORY>/000X-<skecth_name>.dxf

You can change it according to your needs.

In the Text Commands window  (File > View > Show Text Commands or Ctrl-Alt-C) you will get the filenames.

 

Hope this solve you request.

 

Regards,

Jorge

0 Likes
Message 5 of 7

kandennti
Mentor
Mentor

Hi @3d_low .

 

Since I had never tried it, I made a sample that creates a flat pattern and exports a DXF by selecting a face on the sheet metal body.

 

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

EXPORT_PATH = r'C:\temp\FlatPattern.dxf'

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

        # Select Face
        msg: str = 'Select SheetMetal Face'
        selFilter: str = 'Faces'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        # exec FlatPattern command
        app.executeTextCommand(u'Commands.Start FusionSheetMetalFlatPatternCmd')
        app.executeTextCommand(u'NuCommands.CommitCmd')

        # FlatPattern - FlatPatternAssetSubType
        # Find a face
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent
        vp: adsk.core.Viewport = app.activeViewport
        eye: adsk.core.Point3D = vp.camera.eye
        vec: adsk.core.Vector3D = eye.vectorTo(vp.camera.target)
        res = root.findBRepUsingRay(eye, vec, adsk.fusion.BRepEntityTypes.BRepFaceEntityType)
        flatFace: adsk.fusion.BRepFace = res[0]

        # create sketch
        skt: adsk.fusion.Sketch = root.sketches.add(flatFace)

        # export dxf
        skt.saveAsDXF(EXPORT_PATH)

        # exit FlatPattern
        app.executeTextCommand(u'Commands.Start FusionSheetMetalExitFlatPatternCmd')

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


def selectEnt(
        msg: str,
        filterStr: str) -> adsk.core.Selection:

    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None

 

 

I know there are some problems with the details.
(How to determine the difference between a sheet metal body and a normal body, etc.)

 

 

Message 6 of 7

kandennti
Mentor
Mentor
0 Likes
Message 7 of 7

BrianEkins
Mentor
Mentor

Unfortunately, the API does not currently support the flat pattern workspace. The code @kandennti posted is a workaround, but you're still limited in what you can do. Particularly in exporting the flat pattern as DXF. Hopefully, that capability will be coming soon to the API.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes