If you use Fusion 360 for producing sheet metal parts, you'll know that it can create flat pattern DXF files. However these DXF files can be a little confusing as they include the bend extents lines in addition to the bend lines themselves! This can be frustrating because you need to edit the DXF in another program and clean it up before sending the part off for production.

I wrote a quick and dirty Python script to clean up the DXF files so they are closer to what Solidworks generates.

It does two things:

  1. Delete "Bend Extents" lines (or you can edit the script to optionally just hide them)
  2. Change "Bend" layer to use a dashed line style, to differentiate them from the flat pattern's outline

It won't add leaders showing the direction and angle of bends. You'll probably need to edit the DXFs anyway, but it will save time cleaning up the other problems!

Written for and tested with Python 3 on Windows 7

Requires ezdxf which itself requires Python 3.6 or later

Takes DXF filename as command line argument. So for example in Windows you can drag the DXF file and drop it onto the Python script. The DXF file will be edited and overwritten.

# fixDXF v2.0
# deletes BEND_EXTENT elements, changes BEND lines to linetype DASHEDX2
import ezdxf, sys
from ezdxf.tools.standards import linetypes # for predefined line types

if len(sys.argv) < 2: exit() # no file specified

fname = sys.argv[1]
doc = ezdxf.readfile(fname)

# Solution 1:
# Create layer table entry for "BEND_EXTENT" and turn it off
#bend_extents = doc.layers.get('BEND_EXTENT')
#this seems to throw an error... it almost seems the layers are not defined, but the layer table gets built in CAD software after iterating through all elements tagged with that layer name
# workaround is to define a layer with name BEND_EXTENT, then turn it off, then save.
belayer = doc.layers.get('BEND_EXTENT')

# Solution 2:
# query all lines (maybe should query not just lines) with layer "BEND_EXTENT", then delete them, then save.
msp = doc.modelspace()
belines = msp.query('*[layer=="BEND_EXTENT"]')# previously did LINE instead of *, though all bend lines should be LINES
for entity in belines: msp.delete_entity(entity)

# Change bend lines to use dashed linetype
# unless the linetype was predifined in the DXF, would need to define it first
# define linetypes if they don't already exist in the DXF
for name, desc, pattern in linetypes():
    if name not in doc.linetypes:
        doc.linetypes.new(name=name, dxfattribs={'description': desc, 'pattern': pattern})

#bend_lines = doc.layers.get('BEND')
#bend_lines.dxf.linetype = 'DASHEDX2'
# this would have failed too since layer 'BEND' not in the layer table!
doc.layers.new(name='BEND', dxfattribs={'linetype': 'DASHEDX2'})


Some explanation: Bend lines are on layer 'BEND' Bend Extents line are on layer 'BEND_EXTENT'

I prefer to just delete the extents lines instead of hiding them. To hide them, you'd need to define a layers table entry for "BEND_EXTENT" layer, and then turn that layer off. If you try to just turn that layer off without first defining it you will get an error. It seems the Layer table is not predefined in the DXF file exported by Fusion 360, although the elements in the DXF files are assigned to a layer name. CAD programs handle this OK, but ezdxf doesn't.

To change the 'BEND' layer lines to dashed style, the script imports the styles from the ezdxf library and saves them in the DXF. This is necessary, because the DXF file created by Fusion 360 does not come with the different styles predefined.

It would be nice if Fusion 360 would also add leads showing the direction and angle of each bend.

Add a comment

Next Post Previous Post