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


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-152-245b71da2e5a> in <module>()
      6 xy_points_list = []
      7 for polyline in polylines:
----> 8     xy_points = [list(point[0:2]) for point in polyline.points]
      9 
     10     xy_points_list.append(xy_points)

<ipython-input-152-245b71da2e5a> in <listcomp>(.0)
      6 xy_points_list = []
      7 for polyline in polylines:
----> 8     xy_points = [list(point[0:2]) for point in polyline.points]
      9 
     10     xy_points_list.append(xy_points)

TypeError: 'list' object is not callable

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


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-c21261f88bc2> in <module>()
      1 file = './data/rectangle.dxf'
----> 2 dxf = dxfgrabber.readfile(file)
      3 entities = dxf.entities
      4 
      5 

NameError: name 'dxfgrabber' is not defined

In [116]:



Out[116]:
7

In [ ]: