from datetime import datetime
import ezdxf
import os
# Trying to have an hatch with hole.
now = datetime.now()
name = 'test_%d-%d-%d_%d.%d.%d'%(now.year,now.month,now.day,now.hour,now.minute,now.second)+'.dxf'
dwg = ezdxf.new('AC1015') # hatch requires the DXF R2000 (AC1015) format or later
msp = dwg.modelspace() # adding entities to the model space
dwg.layers.new('HATCH', dxfattribs={'linetype': 'Continuous', 'color': 8})
hatch = msp.add_hatch(color=253,dxfattribs={'layer': 'HATCH'})
hatch.set_pattern_fill('AR-CONC',scale=1.,angle=0,style=0,color=0)
with hatch.edit_boundary() as boundary:
# every boundary path is always a 2D element
boundary.add_polyline_path([(0, 0), (1000, 0), (1000, 1000), (0, 1000)], is_closed=1 , flags=1) # External
boundary.add_polyline_path([(300, 300), (700, 300), (700, 700), (300, 700)], is_closed=1 , flags=16) # Internal
filePath, fileName = os.path.split(__file__)
dwg.saveas(filePath+os.sep+name)