Created
February 28, 2024 18:30
-
-
Save tedyapo/925f148f02a639c3c917b9ae782a5513 to your computer and use it in GitHub Desktop.
create a DXF file containing a single polygon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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