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