3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DXFをpythonで読む

Last updated at Posted at 2019-12-11

dxfgrabberを使うとpythonでDXFを読めるらしい
pip install dxfgrabber

フリーの2DCAD jw_cadで適当なDXFファイルを作っておいて,読んでみる.

dxf.py
import dxfgrabber

dxf = dxfgrabber.readfile("test.dxf")
# ヘッダ
print(dxf.header)
# {'$ACADVER': 'AC1009', '$DWGCODEPAGE': 'ANSI_1252', '$INSBASE': (0.0, 0.0, 0.0), '$EXTMIN': (0.0, 0.0), '$EXTMAX': (841.0, 594.0), '$LIMMIN': (0.0, 0.0), '$LIMMAX': (841.0, 594.0), '$LTSCALE': 1.0}

# 図形要素
# print(vars(dxf.entities))
cirs = [e for e in dxf.entities if e.dxftype == 'CIRCLE']
lines = [e for e in dxf.entities if e.dxftype == 'LINE']

# 円
print(vars(cirs[0]))
# {'dxftype': 'CIRCLE', 'handle': None, 'owner': None, 'paperspace': None, 'layer': '_0-0_', 'linetype': 'CONTINUOUS', 'thickness': 0.0, 'extrusion': (0.0, 0.0, 1.0), 'ltscale': 1.0, 'line_weight': 0, 'invisible': 0, 'color': 7, 'true_color': None, 'transparency': None, 'shadow_mode': None, 'layout_tab_name': None, 'center': (94.41901840490794, 356.85030674846627), 'radius': 16.151818630112004}
# centerが円中心のx, y
# radiusが円半径
# linetypeが線種

# 直線
print(vars(lines[0]))
# {'dxftype': 'LINE', 'handle': None, 'owner': None, 'paperspace': None, 'layer': '_0-0_', 'linetype': 'CONTINUOUS', 'thickness': 0.0, 'extrusion': None, 'ltscale': 1.0, 'line_weight': 0, 'invisible': 0, 'color': 7, 'true_color': None, 'transparency': None, 'shadow_mode': None, 'layout_tab_name': None, 'start': (386.4472392638037, 316.28711656441715), 'end': (386.4472392638037, 522.9865030674847)}
# startが始点x,y,endが終点x,y
# linetypeが線種

# 線種一覧(jw_cadの)
print(vars(dxf.linetypes))
# {'_table_entries': {'CONTINUOUS': <dxfgrabber.linetypes.Linetype object at 0x000002B43A5796A0>, 'DASHED1': <dxfgrabber.linetypes.Linetype object at 0x000002B43A5796D8>, 'DASHED2': <dxfgrabber.linetypes.Linetype object at 0x000002B43A579710>, 'DASHED3': <dxfgrabber.linetypes.Linetype object at 0x000002B43A579748>, 'CENTER1': <dxfgrabber.linetypes.Linetype object at ...

参考
https://qiita.com/ackermanrf128/items/d9275a7d077c1dff3ec7

3
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?