我最终让我的绘图程序创建了一个非常基本的Autocad脚本。我提到了this question关于从等高线图中提取x,y数据以编写Autocad脚本。这是相关功能:
def make_autocad_script(outfile_name, contour):
'''
Creates an Autocad script which contains polylines for each contour.
Args
outfile_name: the name of the Autocad script file.
contour: the contour plot that needs to be exported to Autocad.
'''
with open(outfile_name, 'w', newline='') as outfile:
writer = csv.writer(outfile, delimiter=',', )
# each collection is associated with a contour level
for collection in contour.collections:
# If the contour level is never reached, then the collection will be an empty list.
if collection:
# Set color for contour level
outfile.write('COLOR {}\n'.format(random.randint(1,100)))
# Each continuous contour line in