明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4655|回复: 18

决定研究dcl后,第一次练习作

  [复制链接]
发表于 2011-12-24 00:50:23 | 显示全部楼层 |阅读模式
本帖最后由 feng582304 于 2011-12-24 00:57 编辑
  1. (defun feng-dcl-make ( st / file dcl w h )
  2.   (setq file (open (setq dcl (VL-FILENAME-MKTEMP nil nil ".dcl")) "w"))
  3.   (WRITE-LINE st file)
  4.   (close file)
  5.   dcl
  6.   )
  7. (defun c:asdf ( / dcl li )
  8.   (setq dcl (feng-dcl-make
  9.         "feng:dialog {\n
  10.     label = "平面二跑楼梯" ;\n
  11.     spacer_1;\n
  12.     :row {\n
  13.         :edit_box {\n
  14.             key = "heigth" ;\n
  15.             label = "层高:" ;\n
  16.         }\n
  17.         :text {\n
  18.             value = "mm" ;\n
  19.         }\n
  20.     }\n
  21.     :row {\n
  22.         :edit_box {\n
  23.             key = "num" ;\n
  24.             label = "级数:" ;\n
  25.         }\n
  26.         :text {\n
  27.             value = "mm" ;\n
  28.         }\n
  29.     }\n
  30.     :row {\n
  31.         :edit_box {\n
  32.             key = "width1" ;\n
  33.             label = "步宽:" ;\n
  34.         }\n
  35.         :text {\n
  36.             value = "mm" ;\n
  37.         }\n
  38.     }\n
  39.     :row {\n
  40.         :edit_box {\n
  41.             key = "width2" ;\n
  42.             label = "井宽:" ;\n
  43.         }\n
  44.         :text {\n
  45.             value = "mm" ;\n
  46.         }\n
  47.     }\n
  48.     spacer_1;\n
  49.     :row {\n
  50.         :text_part {\n
  51.             value = "踏步高:" ;\n
  52.         }\n
  53.         :text_part {\n
  54.             key = "h1" ;\n
  55.             value = "163.64" ;\n
  56.         }\n
  57.         :text_part {\n
  58.             value = "mm" ;\n
  59.         }\n
  60.     }\n
  61.     spacer_1;\n
  62.     ok_cancel;\n
  63. }"))
  64. ;---------------------------------------------------------------------------------------;
  65. ;  层高-heigth  级数-num  步宽-width1  井宽-width2  踏步高-h1  ;
  66. ;---------------------------------------------------------------------------------------;
  67.   (NEW_DIALOG "feng" (LOAD_DIALOG dcl))
  68.   (MODE_TILE "heigth" 2)
  69.   (SET_TILE "heigth" "3600")
  70.   (SET_TILE "num" "22")
  71.   (SET_TILE "width1" "280")
  72.   (SET_TILE "width2" "120")
  73.   (SET_TILE "h1" (rtos (/ 3600 22.0) 2 2))
  74.   (ACTION_TILE "heigth" "(feng-ht-2stair-hi)")
  75.   (ACTION_TILE "num" "(feng-ht-2stair-hi)")
  76.   (ACTION_TILE "accept" "(setq li (feng-ht-2stair-done))(DONE_DIALOG 1)")
  77.   (if (= (START_DIALOG) 1) (feng-ht-2stair (car li) (cadr li) (last li)))
  78.   )
  79. (defun feng-ht-2stair-done ()
  80.   (setq width1 (FLOAT (read (GET_TILE "width1")))
  81.   width2 (FLOAT (read (GET_TILE "width2")))
  82.   num (read (GET_TILE "num"))
  83.   )
  84.   (list width1 width2 num)
  85.   )
  86. (defun feng-ht-2stair-hi ( / h n )
  87.   (setq h (GET_TILE "heigth")
  88.   n (GET_TILE "num")
  89.   )
  90.   (cond
  91.     ((or (= "" h) (not (VL-EVERY '(LAMBDA (x) (and (>= x 48) (<= x 57))) (VL-STRING->LIST h)))) (SET_TILE "heigth" "参数错误...") (SET_TILE "h1" "参数错误...") (MODE_TILE "heigth" 2))
  92.     ((or (= "" n) (= "0" n) (not (VL-EVERY '(LAMBDA (x) (and (>= x 48) (<= x 57))) (VL-STRING->LIST n)))) (SET_TILE "num" "参数错误...") (SET_TILE "h1" "参数错误...") (MODE_TILE "num" 2))
  93.     (t (SET_TILE "h1" (rtos (/ (FLOAT (read h)) (read n)) 2 2)))
  94.     )
  95.   )
  96. ;-------------------------------------------------------------------------------------------------------------------------------;
  97. ;              通用函数                ;
  98. ;-------------------------------------------------------------------------------------------------------------------------------;
  99. ;坐标转换==》(feng-xytoxy1 目标点 坐标角度 新坐标点 转换开关)  转换开关:非nil时,临时坐标系->ucs,否则是ucs->临时坐标系  ;
  100. ;-------------------------------------------------------------------------------------------------------------------------------;
  101. (defun feng-xytoxy1 ( p ang p0 tt / dt dxy )
  102.   (if (and p0 tt)
  103.     (progn
  104.       (setq p (REVERSE (cons 1 (REVERSE p))))
  105.       (setq dt (list (list (cos ang) (- (sin ang)) 0 (car p0)) (list (sin ang) (cos ang) 0 (cadr p0)) '(0 0 1 0) '(0 0 0 1)))
  106.       )
  107.     (progn
  108.       (setq p (REVERSE (cons 1 (REVERSE (MAPCAR '- p p0)))))
  109.       (setq dt (list (list (cos ang) (sin ang) 0 0) (list (- (sin ang)) (cos ang) 0 0) '(0 0 1 0) '(0 0 0 1)))
  110.       )
  111.     )
  112.   (REVERSE (cdr (REVERSE (MAPCAR
  113.     '(LAMBDA (x)
  114.        (if (and (<= (setq dxy (apply '+ (MAPCAR '* p x))) 1e-05) (>= dxy -1e-05)) 0 dxy)
  115.        )
  116.     dt
  117.     ))))
  118. )
  119. ;---------------------------------------;
  120. ;    预览楼梯    ;
  121. ;---------------------------------------;
  122. (defun feng-ht-2stair-make ( li / ms doc layers )
  123.   (setq ms (vla-get-ModelSpace (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  124.   layers (vla-get-layers doc)
  125.   )
  126.   (if (null (TBLSEARCH "layer" "stair")) (vla-put-color (vla-add layers "stair") 2))
  127.   (MAPCAR '(LAMBDA (x)
  128.        (vla-put-layer (vla-addline ms (vlax-3d-point (car x)) (vlax-3d-point (cadr x))) "stair")
  129.        )
  130.     li
  131.     )
  132.   (redraw)
  133.   )  
  134. (defun feng-ht-2stair ( width1 width3 num / po gpo gr ang ln rn tt ttt li tempo width2 width4 lim-width *ERROR* )
  135.   (defun *ERROR* (msg)
  136.     (redraw)
  137.     )
  138.   (setq po (getpoint "\n请选择楼梯中间平台左角点:")
  139.   ang pi
  140.   ln (fix (/ num 2))
  141.   rn (- num ln)
  142.   tt t
  143.   ttt t
  144.   width2 1200
  145.   )
  146.   (princ "\n---\n")(princ ln)(princ "\n---\n")(princ rn)(princ "\n---end---\n")
  147.   (princ "\n控制参数->角度(A),踏步数(小键盘4/6),平台宽(小键盘2/8)...")
  148.   (while ttt
  149.     (setq gr (grread t 12 2))
  150.     (cond
  151.       ((and (= (car gr) 5) tt) (feng-stair-grvecs
  152.          po
  153.          (setq gpo (abs (cadr (feng-xytoxy1 (if (setq tempo (OSNAP (cadr gr) "_nea")) tempo (cadr gr)) ang po nil))))
  154.          ang
  155.          width1
  156.          (if (<= width2 (setq lim-width (* (1+ (fix (/ (setq width4 (/ (- gpo width3) 2)) 10))) 10))) (setq width2 lim-width) width2)
  157.          width4
  158.          ln
  159.          rn)
  160.        )
  161.       ((and (= (car gr) 5) (null tt)) (feng-stair-grvecs po gpo (setq ang (angle po (if (setq tempo (OSNAP (cadr gr) "_nea")) tempo (cadr gr)))) width1 width2 width4 ln rn))
  162.       ((and (= (car gr) 2) (= (cadr gr) 52)) (if (or (>= (1+ rn) 19) (<= (1- ln) 2)) ln (setq ln (1- ln))) (setq rn (- num ln)));键盘4
  163.       ((and (= (car gr) 2) (= (cadr gr) 54)) (if (or (<= (1- rn) 2) (>= (1+ ln) 19)) ln (setq ln (1+ ln))) (setq rn (- num ln)));键盘6
  164.       ((and (= (car gr) 2) (= (cadr gr) 50)) (if (or (<= 1200 lim-width (setq tempo (- width2 10))) (<= lim-width 1200 tempo)) (setq width2 tempo)));键盘2
  165.       ((and (= (car gr) 2) (= (cadr gr) 56)) (setq width2 (+ width2 10)));键盘8
  166.       ((and (= (car gr) 2) (or (= (cadr gr) 65) (= (cadr gr) 97))) (setq tt nil));键盘A/a
  167.       ((and (= (car gr) 3) (null tt)) (setq tt t))
  168.       ((and (= (car gr) 3) tt) (feng-ht-2stair-make (feng-stair-grvecs po gpo ang width1 width2 width4 ln rn)) (setq ttt nil))
  169.       )
  170.     )
  171.   )
  172. (defun feng-stair-grvecs ( po width ang width1 width2 width3 ln rn / li n )
  173.   (setq n -1)
  174.   (repeat ln
  175.     (setq li (cons (list (list (+ width2 (* (setq n (1+ n)) width1)) 0 0) (list (+ width2 (* n width1)) (- width3 60) 0)) li))
  176.     )
  177.   (setq n -1)
  178.   (repeat rn
  179.     (setq li (cons (list (list (+ width2 (* (setq n (1+ n)) width1)) (- width width3 -60) 0) (list (+ width2 (* n width1)) width 0)) li))
  180.     )
  181.   (setq n (1- (max ln rn)))
  182.   (MAPCAR '(LAMBDA (x) (setq li (cons x li)))
  183.     (list (list (list (- width2 60) (- width3 60) 0) (list (+ width2 (* n width1) 60) (- width3 60) 0))
  184.     (list (list (- width2 60) (- width3 60) 0) (list (- width2 60) (- width width3 -60) 0))
  185.     (list (list (- width2 60) (- width width3 -60) 0) (list (+ width2 (* n width1) 60) (- width width3 -60) 0))
  186.     (list (list (+ width2 (* n width1) 60) (- width3 60) 0) (list (+ width2 (* n width1) 60) (- width width3 -60) 0))
  187.     (list (list width2 width3 0) (list (+ width2 (* n width1)) width3 0))
  188.     (list (list width2 width3 0) (list width2 (- width width3) 0))
  189.     (list (list width2 (- width width3) 0) (list (+ width2 (* n width1)) (- width width3) 0))
  190.     (list (list (+ width2 (* n width1)) width3 0) (list (+ width2 (* n width1)) (- width width3) 0))
  191.     )
  192.     )
  193.   (setq li (MAPCAR '(LAMBDA (x)
  194.           (list (feng-xytoxy1 (car x) ang po t) (feng-xytoxy1 (cadr x) ang po t))
  195.           )
  196.        li
  197.        )
  198.   )
  199.   (redraw)
  200.   (MAPCAR '(LAMBDA (x)
  201.        (GRVECS (cons 2 x))
  202.        )
  203.     li
  204.     )
  205.   li
  206.   )

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

点评

顶,不错!  发表于 2011-12-24 08:12
发表于 2018-1-17 15:27:50 | 显示全部楼层
挺好的,还可动态拉伸
发表于 2017-12-15 16:05:37 | 显示全部楼层
顶你一下顶你一下
发表于 2018-2-25 23:08:05 | 显示全部楼层
初学,观摩一下
发表于 2011-12-24 01:47:21 | 显示全部楼层
半夜睡不着爬起来看帖,顶你一下
发表于 2011-12-24 09:24:42 | 显示全部楼层
支持下,自学成才
 楼主| 发表于 2011-12-24 13:07:15 | 显示全部楼层
谢谢大家支持……
发表于 2011-12-24 13:30:32 | 显示全部楼层
本帖最后由 完整武器 于 2011-12-24 13:33 编辑

很好的程序啊 顶你!!支持楼主继续来个剖面的就完美了!!!
发表于 2011-12-24 17:02:21 | 显示全部楼层
支持一下很不错
 楼主| 发表于 2011-12-25 00:15:04 来自手机 | 显示全部楼层
俺第一个lisp就是画楼梯剖面,现在第一个整合dcl又是楼梯,晕,刚开始也想直接做个剖面的,但没想好要做到哪种功能深度,而且之前那个画剖面的虽没优化,可已用惯了,就算了,做个还没做过的,练习一下刚开始学习的对话框,概念成熟后
发表于 2011-12-26 09:36:13 | 显示全部楼层
本帖最后由 qcw911 于 2011-12-26 09:38 编辑

  1. 这里的内容时怎么写的  \n 怎么加的?




  2.   "feng:dialog {\n
  3.     label = "平面二跑楼梯" ;\n
  4.     spacer_1;\n
  5.     :row {\n
  6.         :edit_box {\n
  7.             key = "heigth" ;\n
  8.             label = "层高:" ;\n
  9.         }\n
  10.         :text {\n
  11.             value = "mm" ;\n
  12.         }\n
  13.     }\n
  14.     :row {\n
  15.         :edit_box {\n
  16.             key = "num" ;\n
  17.             label = "级数:" ;\n
  18.         }\n
  19.         :text {\n
  20.             value = "mm" ;\n
  21.         }\n
  22.     }\n
  23.     :row {\n
  24.         :edit_box {\n
  25.             key = "width1" ;\n
  26.             label = "步宽:" ;\n
  27.         }\n
  28.         :text {\n
  29.             value = "mm" ;\n
  30.         }\n
  31.     }\n
  32.     :row {\n
  33.         :edit_box {\n
  34.             key = "width2" ;\n
  35.             label = "井宽:" ;\n
  36.         }\n
  37.         :text {\n
  38.             value = "mm" ;\n
  39.         }\n
  40.     }\n
  41.     spacer_1;\n
  42.     :row {\n
  43.         :text_part {\n
  44.             value = "踏步高:" ;\n
  45.         }\n
  46.         :text_part {\n
  47.             key = "h1" ;\n
  48.             value = "163.64" ;\n
  49.         }\n
  50.         :text_part {\n
  51.             value = "mm" ;\n
  52.         }\n
  53.     }\n
  54.     spacer_1;\n
  55.     ok_cancel;\n
  56. }"
发表于 2011-12-27 14:47:52 | 显示全部楼层
楼主的代码对我有所启发,谢谢!
 楼主| 发表于 2011-12-27 21:03:36 | 显示全部楼层
qcw911 发表于 2011-12-26 09:36

怎么加\n?很奇怪的问题,不是自己输入进去的吗?晕。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-2-22 17:02 , Processed in 0.209140 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表