Wednesday, September 22, 2021

Mending broken DXFs in Fusion 360

I recently downloaded some DXFs originally designed for use with a CNC machine, with a view to converting them into something suitable for 3D printing. Blender is my go-to for quick manipulations, but in this case I wanted some more advanced tooling and so I decided to use Fusion 360. I had multiple problems, and so I decided to document them here in case this helps others in the same situation. The root cause of most of the problems is disconnected segments. It seems that some programs which output DXFs will leave a small gap between segments. As a result Fusion 360 can't find closed curves and this prevents it doing many important operations such as extruding. The DXF file I am working with is about 4MB and contains around 30 separate items, some for parts such as gears, and a few to illustrate how the parts fit together. I'm only interested in the former. I also tried cutting one part from the sketch into a new sketch for some tests.

You can recognize when there are broken segments if extrude and similar operations are not available, or if you hover over what looks like a closed curve and it does not all highlight. Generally you have to zoom in a long way before you can find the segments that are not joined. If there were only a few of these, fixing them by hand would not be too much of a burden, but when you have each gear has two or four of these per tooth, it quickly becomes time consuming.

A first thing to note is that Fusion 360 has two ways of importing DXFs. In both cases, the result is one or more sketches. The options are:

  • From the Design > Insert menu, there is an Insert DXF function. It seems to be essential to set this to "One sketch per layer" to avoid it taking a very long time. In the file I was working with there were 9 layers.
  • Use the DXF Import Add-in, from the Fusion 360 App Store. I was hopeful about this, as it includes an option to fix the sketch by joining close elements, either on import or as a separate operation. The fixing stage appears to be extremely expensive. I tried importing the large file with the fix option turned on, and after several hours it was still going. I doubt that it would complete in a reasonable time, as by that point Fusion 360 was using around 7GB of RAM, forcing my PC to continually swap and so grind to a halt. With the smaller sketch, I didn't run up against the memory limit, but the fixing stage simply didn't do anything. Note that the Add-in does not allow you to set the units (DXF files don't specify what units they are in), a curious omission.
I then looked at other scripts and add-in designed to fix cases like this. I found three:
  • ConnectTheDots is a Python script. The example video shows it working on exactly the case I wanted. It operates on the selected part of sketch, which I though might allow me to concentrate on just the parts I was interested in. Unfortunately, the script does not work with current versions of Fusion 360. It raises a Python exception. It appears to be unmaintained.
  • ConnectTheDots (another one) is a fork of the original version. It does not raise an exception, but never seems to complete.
  • FillGaps is a paid add-in. It costs $10. There is a free preview version to try it out, though the preview is not very useful as you can't examine the resulting segments. It can join nearby disconnected points by either adding a new segment or merging them. It doesn't take a huge amount of memory, though it can be quite heavy on CPU. It works on the whole of a sketch. Unfortunately, on my large test file it got slower and slower. At the start, the progress bar (which shows percentages) advanced by 1% every 10-15 seconds. From 99% to 100% took multiple minutes, and it then stayed at 100% for an hour and a half until I cancelled it. On the small sketch (cut and paste of a single gear), it finished quickly and accurately. So this looks like a good option, with the inconvenience of having to do a lot of cutting and pasting.
One other option is to load the DXF into blender, select a part from it, convert it to a mesh and then use Blender's Edit Mode operation to combine vertices by distance. This works, but leaves the result as a mesh and in some cases seemed to add some distortion. You can also only export meshes as DXF from Blender and not curves: if you try to export as a curve, then it silently does nothing. However, if you want to continue doing all your modeling in Blender it might work.

A final possibility is to treat the DXF as not being part of the model at all, and just use it to guide creating new sketches with them a guidelines. This isn't great for complex geometry such as gears, but could be combined with the Fusion 360 gear generator add-in to generate gears matching the ones in the DXF.

No comments: