如何使用 python 从坐标写入 dxf 文件?
How can I use python to write a dxf file from coordinates?
我正在尝试使用 ezdxf 从坐标列表中写入一个 dxf 文件。
我可以使用下面的代码绘制一条简单的线来创建一个 dxf 文件:
import ezdxf
doc = ezdxf.new('R2010') # create a new DXF drawing in R2010 fromat
msp = doc.modelspace() # add new entities to the modelspace
msp.add_line((0, 0), (10, 0)) # add a LINE entity
doc.saveas('test_line.dxf')
对于我正在使用的文件,还有一个 "Z" 坐标,根据我在文档中看到的内容,我不知道如何传入。我还想在一行中传递数百个坐标。
试试这个:
import ezdxf
doc = ezdxf.new('R2010') # create a new DXF drawing in R2010 fromat
msp = doc.modelspace() # add new entities to the modelspace
lines = [(0, 0, 0), (10, 0, 0)], [(0, 0, 0), (20, 0, 0)],
for line in lines:
start = line[0]
end = line[1]
msp.add_line(start, end) # add a LINE entity
doc.saveas('test_line.dxf')
它包括 de Z 轴并向文件添加几行。
add_line 参考:https://ezdxf.readthedocs.io/en/master/r12writer.html#ezdxf.r12writer.R12FastStreamWriter.add_line
我正在尝试使用 ezdxf 从坐标列表中写入一个 dxf 文件。
我可以使用下面的代码绘制一条简单的线来创建一个 dxf 文件:
import ezdxf
doc = ezdxf.new('R2010') # create a new DXF drawing in R2010 fromat
msp = doc.modelspace() # add new entities to the modelspace
msp.add_line((0, 0), (10, 0)) # add a LINE entity
doc.saveas('test_line.dxf')
对于我正在使用的文件,还有一个 "Z" 坐标,根据我在文档中看到的内容,我不知道如何传入。我还想在一行中传递数百个坐标。
试试这个:
import ezdxf
doc = ezdxf.new('R2010') # create a new DXF drawing in R2010 fromat
msp = doc.modelspace() # add new entities to the modelspace
lines = [(0, 0, 0), (10, 0, 0)], [(0, 0, 0), (20, 0, 0)],
for line in lines:
start = line[0]
end = line[1]
msp.add_line(start, end) # add a LINE entity
doc.saveas('test_line.dxf')
它包括 de Z 轴并向文件添加几行。
add_line 参考:https://ezdxf.readthedocs.io/en/master/r12writer.html#ezdxf.r12writer.R12FastStreamWriter.add_line