编辑代码

*(format t "Hello world!     -  lisp.jsrun.net") 
;; 定义绘制道路的函数
(defun draw-road (start-point end-point width)
  (command "pline"
           (list (car start-point) (+ (cadr start-point) (/ width 2))) ; 起点上方
           (list (car end-point) (+ (cadr end-point) (/ width 2)))     ; 终点上方
           ""
           )
  (command "pline"
           (list (car start-point) (- (cadr start-point) (/ width 2))) ; 起点下方
           (list (car end-point) (- (cadr end-point) (/ width 2)))     ; 终点下方
           ""
           )
)

;; 定义绘制建筑轮廓的函数
(defun draw-building (corner-points)
  (command "pline")
  (foreach point corner-points
    (command point)
  )
  (command "close")
)

;; 定义绘制管廊的函数
(defun draw-utility-tunnel (center-points width)
  (command "pline")
  (foreach point center-points
    (command (list (- (car point) (/ width 2)) (cadr point))) ; 左侧线
  )
  (command "")
  (command "pline")
  (foreach point center-points
    (command (list (+ (car point) (/ width 2)) (cadr point))) ; 右侧线
  )
  (command "")
)

;; 主程序
(defun c:draw-plan ()
  ;; 设置图层
  (command "layer" "m" "Roads" "c" "1" "" "") ; 创建道路图层
  (command "layer" "m" "Buildings" "c" "2" "" "") ; 创建建筑图层
  (command "layer" "m" "UtilityTunnels" "c" "3" "" "") ; 创建管廊图层

  ;; 绘制道路
  (setq road-start '(0 0)) ; 道路起点
  (setq road-end '(100 0)) ; 道路终点
  (setq road-width 10) ; 道路宽度
  (draw-road road-start road-end road-width)

  ;; 绘制建筑
  (setq building-corners '((20 20) (20 40) (40 40) (40 20))) ; 建筑轮廓点
  (draw-building building-corners)

  ;; 绘制管廊
  (setq tunnel-points '((10 10) (30 10) (30 30) (10 30))) ; 管廊中心线点
  (setq tunnel-width 5) ; 管廊宽度
  (draw-utility-tunnel tunnel-points tunnel-width)

  ;; 添加标注
  (command "text" (list 50 5) 2 0 "奔竞大道") ; 标注道路名称
  (command "text" (list 30 25) 2 0 "运动员公寓") ; 标注建筑名称
  (command "text" (list 20 15) 2 0 "电力管廊") ; 标注管廊名称

  (princ "\n杭州亚运村地下综合管廊平面图已生成!")
)