CauldronDevelopmentLLC / CAMotics

Open-Source Simulation & Computer Aided Machining - A 3-axis CNC GCode simulator
Other
602 stars 138 forks source link

DXF import in 1.2.0 won't accept OpenSCAD DXF output #362

Closed cbiffle closed 2 years ago

cbiffle commented 2 years ago

Given a simple 2D piece in OpenSCAD (2021.01), e.g.

square([10, 10]);

CAMotics (1.2.0) via TPL will not load the results of exporting to DXF. The following TPL statement:

var layers = dxf.open('whatever.dxf');

reliably fails with the message

ERROR:Exception: DXF Undefined layer '0'

Loading the DXF file into Inkscape and saving without apparent changes alters the format and causes it to start working with CAMotics. I'm not familiar enough with the DXF format to explain the changes Inkscape makes, though it certainly inserts a bunch of stuff.

jcoffland commented 2 years ago

So the problem is that the DXF created by OpenSCAD does not define any layers. dxflib defaults to layer 0 if no layer is specified by the file. When it tries to add an entity to layer 0 you get the error you mentioned above. I don't know if OpenSCAD is creating an incorrect DXF file or if dxflib is handling it incorrectly. However, if I just automatically add the missing layer in the code it seems to work fine. This will be fixed in the next release. See the associated commit.