Skip to content

Instantly share code, notes, and snippets.

@augustt198
Created May 29, 2017 04:20
Show Gist options
  • Save augustt198/26508851b5a5f830dfa8a2e5b022b1bc to your computer and use it in GitHub Desktop.
Save augustt198/26508851b5a5f830dfa8a2e5b022b1bc to your computer and use it in GitHub Desktop.
DRL NC file to DXF
from dxfwrite import DXFEngine as dxf
from sys import argv
import re
if len(argv) < 2:
print("Need filename")
in_filename = argv[1]
out_filename = in_filename[:-4] + ".dxf"
drawing = dxf.drawing(out_filename)
drawing.add_layer('holes')
tools = {}
current_tool = None
for line in open(in_filename).readlines():
line = line.strip()
match = re.match("^T(\d+)C(.+)$", line)
if match:
tool_id = int(match.group(1))
size = float(match.group(2))
tools[tool_id] = size
continue
match = re.match("^T(\d+)$", line)
if match:
current_tool = int(match.group(1))
continue
match = re.match("^X(.+)Y(.+)$", line)
if match:
x = float(match.group(1))
y = float(match.group(2))
size = tools[current_tool]
drawing.add(dxf.circle(radius=size/2, center=(x, y), layer='holes'))
print("Tools:")
print(tools)
drawing.save()
@ambienthack
Copy link

Very helpful, thank you!

@LeonardoCT
Copy link

Hello, when i try to use this script all the coordinates are wrong and it makes the drawing huge, how i can fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment