Skip to content

Instantly share code, notes, and snippets.

@schoeller
Created January 30, 2017 21:15
Show Gist options
  • Save schoeller/2ed175c582973c85f762d1b26c0b1cce to your computer and use it in GitHub Desktop.
Save schoeller/2ed175c582973c85f762d1b26c0b1cce to your computer and use it in GitHub Desktop.
Script to convert STL mesh to 3dfaces in DXF-format
import sys
# Writing STL mesh to 3dfaces as DXF using dxfwrite
# Dirty script thus only for triangles
from dxfwrite import DXFEngine as dxf
drawing = dxf.drawing('test.dxf')
for line in sys.stdin.readlines():
if line.find(" facet") == 0:
point = []
face3d = []
if line.find("vertex") != -1:
point.append(line.split()[-3:])
if line.find(" endfacet") == 0:
face3d = dxf.face3d(point)
face3d['layer'] = 'faces'
face3d['color'] = 7
drawing.add(face3d)
drawing.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment