read.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import ezdxf
  2. # Load the DXF file
  3. doc = ezdxf.readfile("cube.dxf")
  4. # 遍历 DXF 文件中的所有实体
  5. Points = None
  6. rad = None
  7. for entity in doc.modelspace():
  8. # 输出实体类型
  9. print("实体类型:", entity.dxftype())
  10. print( entity.dxf.layer)
  11. if entity.dxf.layer =='办公楼':
  12. if entity.dxftype() == "HATCH":
  13. a = entity.paths
  14. b = entity.paths[0]
  15. print(entity.paths[0].vertices)
  16. # 根据实体类型输出参数
  17. if entity.dxftype() == "LINE":
  18. print("句柄:", entity.dxf.handle)
  19. print("起点坐标:", entity.dxf.start)
  20. print("终点坐标:", entity.dxf.end)
  21. elif entity.dxftype() == "CIRCLE":
  22. print("句柄:", entity.dxf.handle)
  23. print("圆心坐标:", entity.dxf.center)
  24. print("半径:", entity.dxf.radius)
  25. # 保存半径
  26. rad = entity.dxf.radius
  27. elif entity.dxftype() == "LWPOLYLINE":
  28. print("句柄:", entity.dxf.handle)
  29. vertices = entity.get_points("xy")
  30. print("顶点坐标列表:", vertices)
  31. # 保存顶点坐标
  32. Points = vertices
  33. print()
  34. """
  35. 实体类型: LWPOLYLINE
  36. 句柄: 2B6
  37. 顶点坐标列表: [(1849.874614722246, 2126.668048160624), (2049.874614722247, 2126.668048160624), (2049.874614722247, 1926.668048160624), (1849.874614722246, 1926.668048160624)]
  38. 实体类型: CIRCLE
  39. 句柄: 2B7
  40. 圆心坐标: (1949.874614722246, 2026.668048160624, 0.0)
  41. 半径: 99.99999999999979
  42. """