明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1338|回复: 3

[提问] 菜鸟问个lisp/DCL的问题

[复制链接]
发表于 2016-2-13 00:25:25 | 显示全部楼层 |阅读模式
本帖最后由 福建师大附中 于 2016-2-13 00:31 编辑

  1. mjbz:dialog{
  2.               label="面积标注插件";
  3.               :text{
  4.                               label="zhw--12测绘";
  5.                         alignment=centered;    //向中对齐
  6.                    }
  7.                :boxed_row{
  8.                                label="字体高度设定";
  9.                                fixed_width=true;
  10.                                alignment=centered;
  11.                         :edit_box{                        //编辑框对象
  12.                                               label="字高";    //编辑框卷标
  13.                                               key="txtzg";
  14.                                                edit_width=10;   //编辑框高度
  15.                                         }
  16.                                :popup_list{
  17.                                                key="popzg";
  18.                                                edit_width=10;
  19.                                           }
  20.                                 }
  21.                                 
  22.                :boxed_row{
  23.                                label="小数点设定";
  24.                                fixed_width=true;
  25.                                alignment=centered;
  26.                         :edit_box{                        //编辑框对象
  27.                                                 label="小数点";    //编辑框卷标
  28.                                               key="txtxsd";
  29.                                                edit_width=10;   //编辑框高度
  30.                                         }
  31.                                :popup_list{
  32.                                                key="popxsd";
  33.                                                edit_width=10;
  34.                                           }
  35.                                }
  36.                               
  37.               :boxed_row{
  38.                                label="标注单位";
  39.                                :button{
  40.                                              label="平方米标注";
  41.                                              key="pfmbz";
  42.                                      }
  43.                                :button{
  44.                                        label="亩标注";
  45.                                        key="mbz";
  46.                                      }
  47.                                :button{
  48.                                        label="公顷标注";
  49.                                        key="gqbz";
  50.                                        }
  51.                              }
  52.               spacer_1;                //空白一行
  53.               ok_cancel;
  54.               }[code=lisp](defun c:mjbz()
  55.   (setvar "cmdecho" 0)
  56.   (setq popzg_list '("1" "2" "3" "4" "5" "8" "10" "12" "15" "20" "30"))
  57.   (chk_style)
  58.   (dcl_mjbz)
  59.   (prin1)
  60. )

  61. (defun dcl_mjbz()
  62.   (setq dcl_id (load_dialog "f:\\a\\chugao.dcl"))
  63.   (new_dialog "mjbz" dcl_id)
  64.   (show_list "popzg" popzg_list)      ;显示字高下拉框
  65.   (set_tile "txtzg" "1")              ;预设字高文字框显示为“1”
  66.   (action_tile "popzg" "(sub_popzg $value)")              ;触发DCL对象,并执行其后指定动作,同时产生六个变量
  67.   (action_tile "pfmbz" "(sub_pfmbz)(done_dialog 2)")
  68.   (action_tile "mbz" "(sub_mbz)(done_dialog 3)")
  69.   (action_tile "gqbz" "(sub_gqbz)(done_dialog 4)")
  70.   (setq dd(start_dialog))               ;将控制权交给DCL
  71.   (cond
  72.       ((= dd 2)
  73.       (setq pt (getpoint"\请点取计算面积书写位置:" ))
  74.       (SETQ STA (BPOLY PT))
  75.       (IF (= STA NIL) (EXIT))         ;因AutoCAD的原因,有可能找不到边界
  76.       (COMMAND "AREA" "E" "L")
  77.       (SETQ QAREA (rtos (GETVAR "AREA") 2 3))   ;最后面的数字2是十进制,3是控制标注的小数点位数
  78.       (command "layer" "m" "面积" "c" "" "" "")
  79.       (COMMAND "TEXT" PT txtzg "0" (strcat QAREA "平方米"))  ;1字体大小,0角度
  80.       )
  81.       ((= dd 3)
  82.       (setq pt (getpoint"\请点取计算面积书写位置:" ))
  83.       (SETQ STA (BPOLY PT))
  84.       (IF (= STA NIL) (EXIT))         ;因autocad的原因,有可能找不到边界
  85.       (COMMAND "AREA" "E" "L")
  86.       (SETQ QAREA (rtos (* (/ (GETVAR "AREA") 10000) 15) 2 3))   ;最后面的数字2是十进制,3是控制标注的小数点位数
  87.       (command "layer" "m" "面积" "c" "" "" "")
  88.       (COMMAND "TEXT" PT txtzg "0" (strcat QAREA "亩"))  ;1字体大小,0角度
  89.       )
  90.       ((= dd 4)
  91.       (setq pt (getpoint"\请点取计算面积书写位置:" ))
  92.       (SETQ STA (BPOLY PT))
  93.       (IF (= STA NIL) (EXIT))         ;因autocad的原因,有可能找不到边界
  94.       (COMMAND "AREA" "E" "L")
  95.       (SETQ QAREA (rtos (/ (GETVAR "AREA") 10000) 2 3))   ;最后面的数字2是十进制,3是控制标注的小数点位数
  96.       (command "layer" "m" "面积" "c" "" "" "")
  97.       (COMMAND "TEXT" PT txtzg "0" (strcat QAREA "公顷"))  ;1字体大小,0角度
  98.       )
  99.     )
  100.   )

  101. (defun show_list(key newlist)     ;调用显示选单数据子程序
  102.   (start_list key)            ;;;;;;;;;开始处理选单对象
  103.   (mapcar 'add_list newlist)   ;逐一加入信息至选单
  104.   (end_list)                   ;结束处理选单
  105.   )

  106. (defun sub_popzg(vvs)
  107.   (set_tile "txtzg" (nth (atoi vvs) popzg_list))         ;设定字高编辑框
  108.   )

  109. (defun sub_pfmbz()
  110.   (setq txtzg (get_tile "txtzg"))
  111.   (setq txtxsd (get_tile "txtxsd"))
  112.   )

  113. (defun sub_mbz()
  114.   (setq txtzg (get_tile "txtzg"))
  115.   (setq txtxsd (get_tile "txtxsd"))
  116.   )

  117. (defun sub_gqbz()
  118.   
  119.   (setq txtzg (get_tile "txtzg"))
  120.   (setq txtxsd (get_tile "txtxsd"))
  121.   )

  122. (defun chk_style()   ;检查字型
  123.   (setq chksty (tblsearch "style" "Standard"))
  124.   (if (null chksty)                                 ;如果不存在,则新建字形
  125.     (command "_style" "Standard" "宋体" "" "" "" "" "")
  126.     )
  127.   (setq chklay (tblsearch "layer" "面积"))        ;检测图层是否存在
  128.   (if (null chklay)                              ;如果不存在,则新建图层
  129.     (command "_layer" "m" "面积" "c" "3" "面积" "")
  130.     )
  131.   (setvar "clayer" "面积")                        ;预设目前图层
  132.   (setvar "textstyle" "Standard")                       ;预设目前字形
  133.   )
[/code]

想要插入一段能够改变面积的小数点位数的编码(如0.0,0.00,0.000,0.0000),应该要怎么写


发表于 2016-2-13 09:16:39 | 显示全部楼层
  1. mjbz:dialog{
  2. label="面积标注插件";
  3. alignment=centered; //向中对齐
  4. :text{label="zhw--12测绘";}
  5. :popup_list{label="字高";key="popzg";edit_width=10;}
  6. :popup_list{label="小数点";key="popxsd";edit_width=10;}
  7. :radio_row{
  8.   label="标注单位";
  9.   key="bzdw";
  10.   :radio_button{label="平方米";key="pfmbz";value=1;}
  11.   :radio_button{label="亩";key="mbz";value=0;}
  12.   :radio_button{label="公顷";key="gqbz";value=0;}
  13. }
  14. spacer_1;                //空白一行
  15. ok_cancel;
  16. }
  1. (defun c:mjbz()
  2.   (setvar "cmdecho" 0)
  3.   (setq popzg_list '("1" "2" "3" "4" "5" "8" "10" "12" "15" "20" "30"))
  4.   (setq popxsd_list '("0.0" "0.00" "0.000" "0.0000" "0.00000" "0.000000" "0.0000000"))
  5.   (chk_style)
  6.   (dcl_mjbz)
  7.   (prin1)
  8. )
  9. (defun readata ()
  10. (setq bzdw (get_tile "bzdw"))
  11. (setq bl (cond((= bzdw "pfmbz") 1)((= bzdw "mbz") (/ 10000 15.0))((= bzdw "gqbz") 10000)))
  12. (setq bzdw (cond((= bzdw "pfmbz") "平方米")((= bzdw "mbz") "亩")((= bzdw "gqbz") "公顷")))
  13. (setq txtzg (itoa (nth (itoa (get_tile "popzg")) popzg_list)))
  14. (setq xsd (1+ (itoa (get_tile "popxsd"))))
  15. )
  16. (defun dcl_mjbz()
  17. (if (> (setq dcl_id (load_dialog "mjbz.dcl")) 0) (progn
  18.   (if (new_dialog "mjbz" dcl_id) (progn
  19.   (show_lst "popzg" popzg_list)
  20.   (set_tile "popzg" "0")
  21.   (show_lst "popxsd" popxsd_list)
  22.   (set_tile "popxsd" "2")
  23.   (action_tile "cancel" "(done_dialog 0)")
  24.   (action_tile "accept" "(readata)(done_dialog 1)")
  25.   (setq dd(start_dialog))               ;将控制权交给DCL
  26.   )
  27.    (princ "\n无法显示对话框!")
  28.   )
  29.   (unload_dialog dcl_id)
  30. )
  31.   (princ "\n无法加载对话框!")
  32. )
  33. (if (= dd 1) (progn
  34.   (setq pt (getpoint "\请点取计算面积书写位置:" ))
  35.   (if (setq STA (bpoly PT)) (progn
  36.    (command "AREA" "E" "L")
  37.    (setq QAREA (rtos (/ (getvar "AREA") bl) 2 xsd)) ;2 = 十进制,xsd = 小数点位数
  38.    (command "TEXT" PT txtzg "0" (strcat QAREA bzdw))  ;txtzg=字高,0角度
  39.   ))
  40. ))
  41. )
  42. (defun show_list(key newlist) ;调用显示选单数据子程序
  43. (start_list key)             ;开始处理选单对象
  44. (mapcar 'add_list newlist)   ;逐一加入信息至选单
  45. (end_list)                   ;结束处理选单
  46. )
  47. (defun chk_style()   ;检查字型
  48. (setq chksty (tblsearch "style" "Standard"))
  49. (if (null chksty)                                 ;如果不存在,则新建字形
  50.   (command "_style" "Standard" "宋体" "" "" "" "" "")
  51. )
  52. (command "_layer" "m" "面积" "c" "3" "" "")
  53. (setvar "clayer" "面积")                        ;预设目前图层
  54. (setvar "textstyle" "Standard")                 ;预设目前字形
  55. )
发表于 2016-2-13 11:20:26 | 显示全部楼层
本帖最后由 kewyst 于 2016-2-13 13:41 编辑

很不错啊,看见大神的回复,正在学习dcl,能把dcl打包到lsp里面吗?

(setq txtzg (itoa (nth (itoa (get_tile "popzg")) popzg_list))) 这句有问题!
(defun show_list(key newlist)    (show_lst "popzg" popzg_list) 也有问题
发表于 2016-3-24 20:42:07 | 显示全部楼层
本帖最后由 feng83 于 2016-3-24 20:43 编辑

(defun c:mjbz()
  (setvar "cmdecho" 0)
  (setq popzg_list '("1" "2" "3" "4" "5" "8" "10" "12" "15" "20" "30"))
  (setq popxsd_list '("0.0" "0.00" "0.000" "0.0000" "0.00000" "0.000000" "0.0000000"))
  (chk_style)
  (dcl_mjbz)
  (prin1)
)
(defun readata ()
  (setq bzdw (get_tile "bzdw"))
  (setq bl (cond((= bzdw "pfmbz") 1)
                ((= bzdw "mbz") (/ 10000 15.0))
                ((= bzdw "gqbz") 10000)))
  (setq bzdw (cond((= bzdw "pfmbz") "平方米")
                  ((= bzdw "mbz") "亩")
                  ((= bzdw "gqbz") "公顷")))
  (setq txtzg (nth (atoi (get_tile "popzg")) popzg_list)  )
  (setq xsd (1+ (atoi (get_tile "popxsd"))))
  )
(defun dcl_mjbz()
(if (> (setq dcl_id (load_dialog "c:/mjbz.dcl")) 0)
   (progn
     (if (new_dialog "mjbz" dcl_id)
       (progn
         (show_list "popzg" popzg_list)
         (set_tile "popzg" "0")
         (show_list "popxsd" popxsd_list)
         (set_tile "popxsd" "2")
         (action_tile "cancel" "(done_dialog 0)")
         (action_tile "accept" "(readata)(done_dialog 1)")
         (setq dd(start_dialog))               ;将控制权交给DCL
         )
       (princ "\n无法显示对话框!")
       )
     (unload_dialog dcl_id)
     )
   (princ "\n无法加载对话框!")
   )
  (if (= dd 1)
    (progn
      (setq pt (getpoint "\请点取计算面积书写位置:" ))
      (if (setq STA (bpoly PT))
        (progn
          (command "AREA" "E" "L")
          (setq QAREA (rtos (/ (getvar "AREA") bl) 2 xsd)) ;2 = 十进制,xsd = 小数点位数
          (command "TEXT" PT txtzg "0" (strcat QAREA bzdw))  ;txtzg=字高,0角度
          ))
      ))
  )
(defun show_list(key newlist) ;调用显示选单数据子程序
(start_list key)             ;开始处理选单对象
(mapcar 'add_list newlist)   ;逐一加入信息至选单
(end_list)                   ;结束处理选单
)
(defun chk_style()   ;检查字型
(setq chksty (tblsearch "style" "Standard"))
(if (null chksty)                                 ;如果不存在,则新建字形
  (command "_style" "Standard" "宋体" "" "" "" "" "")
)
(command "_layer" "m" "面积" "c" "3" "" "")
(setvar "clayer" "面积")                        ;预设目前图层
(setvar "textstyle" "Standard")                 ;预设目前字形
)
只是改了几处错误,让程序可以运行







您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-20 13:43 , Processed in 0.208431 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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