test.py 501 B

123456789101112131415161718192021
  1. import ezdxf
  2. from ezdxf import path
  3. # 创建 DXF 文档
  4. doc = ezdxf.new(dxfversion='R2018')
  5. msp = doc.modelspace()
  6. # 定义填充边界
  7. boundary_points = [(0, 0), (50, 0), (50, 30), (0, 30)]
  8. # 创建 HATCH 实体
  9. hatch = msp.add_hatch(color=1)
  10. hatch.set_pattern_fill(name='GRAVEL', scale=0.5, angle=45)
  11. # 新版本直接添加多段线路径,无需 flags 参数
  12. hatch.paths.add_polyline_path(
  13. boundary_points,
  14. is_closed=True # 只需确保闭合即可
  15. )
  16. doc.saveas("hatch_example.dxf")