Skip to content

Instantly share code, notes, and snippets.

@tedyapo
Created February 28, 2024 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedyapo/925f148f02a639c3c917b9ae782a5513 to your computer and use it in GitHub Desktop.
Save tedyapo/925f148f02a639c3c917b9ae782a5513 to your computer and use it in GitHub Desktop.
create a DXF file containing a single polygon
import numpy as np
class DXFPolygon:
def __init__(self, x, y):
self.x = x
self.y = y
def write(self, filename):
x = self.x
y = self.y
with open(filename, 'wt') as fout:
fout.write('0\n')
fout.write('SECTION\n')
fout.write('2\n')
fout.write('ENTITIES\n')
fout.write('0\n')
fout.write('POLYLINE\n')
fout.write('70\n')
fout.write('1\n') # closed polyline
fout.write('40\n')
fout.write('0\n') # start width
fout.write('41\n')
fout.write('0\n') # end width
for i in range(x.shape[0]):
fout.write('0\n')
fout.write('VERTEX\n')
fout.write('10\n')
fout.write(f'{x[i]}\n')
fout.write('20\n')
fout.write(f'{y[i]}\n')
fout.write('0\n')
fout.write('SEQEND\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment