In [150]:
import dxfgrabber
import dxfwrite
In [152]:
pointsfile = './sampledata/cat.dxf'
dxf = dxfgrabber.readfile(pointsfile)
entities = dxf.entities
polylines = [entity for entity in entities if entity.dxftype == 'POLYLINE']
xy_points_list = []
for polyline in polylines:
xy_points = [list(point[0:2]) for point in polyline.points]
xy_points_list.append(xy_points)
xy_points_list
In [21]:
# read dxf file
star = dxfgrabber.readfile('./data/star.dxf')
# read entities
entities = star.entities
# read xy points list
list_of_vertices = [entity.points for entity in entities]
In [23]:
def get_vertices(file):
"""
dxfファイルを渡して、座標のタプルのリストを返す
:param file: dxf file
:return: tuple's list of vertices(x,y,z)
"""
star = dxfgrabber.readfile(file)
entities = star.entities
# list of x,y,z coodinates
list_of_vertices = [entity.points for entity in entities]
# list of x,y coodinates
# list_of_vertices[0] == 2次元配列のうち利用するのは最初の一つだけ。
list_of_xy = [vertix[0:2] for vertix in list_of_vertices[0]]
return list_of_xy
In [1]:
file = './data/rectangle.dxf'
dxf = dxfgrabber.readfile(file)
entities = dxf.entities
In [116]:
Out[116]:
In [ ]: