import ezdxf
doc = ezdxf.new(dxfversion='R2018')
msp = doc.modelspace()
doc.layers.add("WALL", color=1)
doc.layers.add("STAIR", color=4)
doc.layers.add("DIM", color=2)
core_x = 8100 - 2400 - 240
core_y_start = 11500 - 4500
floor_heights = [0, 3600, 6900, 10200, 13500, 16800]
def draw_stairs(msp, floor, floor_height):
"""差异化绘制楼梯"""
stair_tread = 260
if floor == 0:
stair_riser = 172
steps = 21
mid_platform = 10
else:
stair_riser = 165
steps = 20
mid_platform = 9
start_x = core_x + 240
start_y = core_y_start + 240
for i in range(steps):
y = start_y + i * stair_riser
x = start_x + i * stair_tread
msp.add_line((x, y), (x + stair_tread, y + stair_riser),
dxfattribs={'layer': 'STAIR'})
if (floor == 0 and i == mid_platform) or (floor > 0 and i == mid_platform):
msp.add_lwpolyline(
[(x + stair_tread, y + stair_riser),
(x + stair_tread + 1200, y + stair_riser),
(x + stair_tread + 1200, y + stair_riser + 1200),
(x + stair_tread, y + stair_riser + 1200)],
dxfattribs={'layer': 'STAIR'}
)
for floor in range(5):
draw_stairs(msp, floor, floor_heights[floor])
msp.add_mtext(
f"FL{floor+1} 层高: {3600 if floor==0 else 3300}mm\n标高: {floor_heights[floor]}mm",
dxfattribs={'layer': 'DIM', 'char_height': 250}
).set_location((core_x - 2000, core_y_start - 1000))
doc.saveas("差异化层高楼梯.dxf")