12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import ezdxf
- # Load the DXF file
- doc = ezdxf.readfile("cube.dxf")
- # 遍历 DXF 文件中的所有实体
- Points = None
- rad = None
- for entity in doc.modelspace():
- # 输出实体类型
- print("实体类型:", entity.dxftype())
- print( entity.dxf.layer)
- if entity.dxf.layer =='办公楼':
- if entity.dxftype() == "HATCH":
- a = entity.paths
- b = entity.paths[0]
- print(entity.paths[0].vertices)
- # 根据实体类型输出参数
- if entity.dxftype() == "LINE":
- print("句柄:", entity.dxf.handle)
- print("起点坐标:", entity.dxf.start)
- print("终点坐标:", entity.dxf.end)
- elif entity.dxftype() == "CIRCLE":
- print("句柄:", entity.dxf.handle)
- print("圆心坐标:", entity.dxf.center)
- print("半径:", entity.dxf.radius)
- # 保存半径
- rad = entity.dxf.radius
- elif entity.dxftype() == "LWPOLYLINE":
- print("句柄:", entity.dxf.handle)
- vertices = entity.get_points("xy")
- print("顶点坐标列表:", vertices)
- # 保存顶点坐标
- Points = vertices
- print()
- """
- 实体类型: LWPOLYLINE
- 句柄: 2B6
- 顶点坐标列表: [(1849.874614722246, 2126.668048160624), (2049.874614722247, 2126.668048160624), (2049.874614722247, 1926.668048160624), (1849.874614722246, 1926.668048160624)]
- 实体类型: CIRCLE
- 句柄: 2B7
- 圆心坐标: (1949.874614722246, 2026.668048160624, 0.0)
- 半径: 99.99999999999979
- """
|