明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1474|回复: 5

高手看下哪里有问题 (LSP&DCL)

[复制链接]
发表于 2008-2-20 14:30 | 显示全部楼层 |阅读模式

从网上down了以下程序在ACAD2005中加载后,提示如下:

命令: APPLOAD 已成功加载 initest.lsp。
命令: ; 错误: 输入的列表有缺陷



LSP代码如下:
---------------------------------------------------------------------------------------
(defun c:initset ()
 (setq flag 0)
 (setq dcl-id (load-dialog "init.dcl"))
 (if (not (new-dialog "init" dcl-id) (exit)) ;;begin if
     (action-tile "list-size" "(list-size-cb $value)")
     (action-tile "list-scale" "(scal-list-cb $value)")
     (action-tile "accept" "(scal-accept-cb)")
     (setq lisca' ("1:1" "1:1.5" "1:2" "1:2.5" "1:3" "1:4" "1:5" "2:1" "2.5:1" "3:1" "4:1" "5:1"))
     (start-list "list-scale")
     (mapcar' add-list lisca)
     (end-list)
     (set-tile "edit-scale" "1:1")
     (setq lisize' ("A0 1189X841" "A1 841X594" "A2 594X420" "A3 420X297" "A4 210X297" "A5 210X148" "user用户自定义"))
     (start-list "list-size")
     (mapcar' add-list lisize)
     (end-list)
     (set-tile "edit-size" "A0")
     (start-dialog)
     (unload-dialog dcl-id)
     (grclear)
     (if (=flag 0)
         (quit)
     )
     (sett x1 y1 a c name scale tfb)
   ) ;;end if


 (defun scal-list-cb(scale-v) ; 比例对应回调函数
  (set-tile "edit-scale" (setq tu (nth (atoi scale-v) lisca)))
 ) 
 
 (defun list-size-cb(tub1) ; 图幅对应回调函数
     (if (=tub1 "0") (mapcar 'set' '(tu1 x1 y1 c) '("A0" 1189 841 10)))
     (if (=tub1 "1") (mapcar 'set' '(tu1 x1 y1 c) '("A1" 841 594 10)))
     (if (=tub1 "2") (mapcar 'set' '(tu1 x1 y1 c) '("A2" 594 420 10)))
     (if (=tub1 "3") (mapcar 'set' '(tu1 x1 y1 c) '("A3" 420 297 10)))
     (if (=tub1 "4") (mapcar 'set' '(tu1 x1 y1 c) '("A4" 210 297 5)))
     (if (=tub1 "5") (mapcar 'set' '(tu1 x1 y1 c) '("A5" 210 148 5)))
     (if (=tub1 "6") (progn (setq tu1 "user")
     (define))) (set-tile "edit-size" tu1)
 )
 
 (defun scal-accept-cb(); OK对应回调函数
     (setq scale (get-tile "edit-scale"))
     (setq name (get-tile "st-0"))
     (setq tufb (get-tile "edit-size"))
     (setq tfb (get-tile "1-0"))
     (setq ede (get-tile "e-0"))
     (if (= ede "1") (setq a 25) (setq a 10))
     (setq flag 1) (done-dialog 1)
 )
 
 (defun sett(x y a c name scale tfb1)
     (setq 1 (strlen scale))
         (setq n (substr scale 1 1))
     (if (> n "1")
         (progn
             (setq 11 (-1 2))
      (setq scale1 (/1.0 (atof (substr scale 1 11))))
   )
  (setq scale1 (atof (substr scale 3)))
     )
     (setq x (* x scale1)) ;图幅大小
     (setq y (* y scale1))
     (setq c (* scale1))
     (setq a (* a scale1))
     (if (/= tfb1 "1")
         (progn  ;设置图纸方式
             (setq t x)
             (setq x y)
             (setq y t)
         )
      )
     (setvar "cmdecho" 0)  ;设置图层线型和颜色
     (command "linetype" "1" "center" "acad"\r "1" "hidden" "acad" \r "1" "phantom" \r \r)
     (setq lay "dimension, linehidden, linephantom, line-center, linesection, line-thin, part")
     (command "layer" "n" lay "c" "1" "linehidden" "c" "4" "dimension" "c" "5" "linephantom" "c" "5" "line-center" "c" "3" "linesection" "c" "2" "line-thin" "1" "center" "line-center" "1" "hidden" "linehidden" "1" "phantom" "linephantom" \r \r)
     (setq 1t (* 8 scale1)) (command "ltscale" 1t)
     (setq pt1 (list 0 0)); 绘制图框
     (setq pt2 (list x y))
     (setq pt3 (list x 0))
     (setq pt4 (list 0 y))
     (setq pt5 (list a c))
     (setq pt6 (list (- x c) (- y c)))
     (setq pt7 (list (- x c) c))
     (setq pt8 (list a (-y c)))
     (command "layer" "s" "line-thin" \r \r)
     (command "line" pt1 pt3 pt2 pt4 "c")
     (command "layer" "s" "part" \r \r)
     (command "line" pt5 pt7 pt6 pt8 "c")
     (command "zoom" "a")
     ;选择标题栏形式TAB1,TAB2是已定义好的标题栏块
     (if (=name "1")
         (setq name1 "tab1")
         (setq name1 "tab2")
     )
     (setq r1 0)
     (setq pt7 (list (- x c) c))
     (command "insert" name1 pt7 scale1 scale1 r1)
     (setq li (* scale1 7))   ;尺寸标注初始化
     (setq se (* scale1 3.5))
     (setq xe (* scale1 2))
     (setq xt (* scale1 3.2))
     (setvar "dimclrd" 4)
     (setvar "dimclre" 4)
     (setvar "dimclrt" 7)
     (command "dim" "dimtof1" "1")
     (command "dimdli" li)
     (command "dimase" se)
     (command "exit")
     (setvar "dimexe" xe)
     (setvar "dimse1" 0)
     (setvar "dimse2" 0)
     (setvar "dimtxt" xt)
     (setvar "dimtfac" 0.5)
     (setvar "dimtix" 1)
     (setvar "dimsoxd" 0)
     (setvar "dimtad" 1)
     (setvar "dimtih" 0)
     (setvar "dimtoh" 0)
     (setvar "dimasz" xt)
     (setvar "cmdecho" 1)
 )
 (defun define ()  ;自定义图幅函数
     (setq dc1-id (load-dialog "init.dc1"))
     (new-dialog "define" dcl-id)
     (action-tile "accept" "(ok-cb)")
     (setq x2 (dimx-tile "image"))
     (setq y2 (dimy-tile "image"))
     (start-image "image")
     (fill-image 0 0 x2 y2-1)
     (silde-image 0 0 x2 y2 "init.sld")
     (end-image)
     (start-dialog)
     (unload-dialog dc1-id)
 )
 (defun ok-cb ()   ;自定义图幅OK回调函数
     (setq y1 (atof (get-tile "b")))
     (setq x1 (atof (get-tile "1")))
     (setq a (atof (get-tile "a")))
     (setq c (atof (get-tile "c")))
     (setq flag 1)
     (done-dialog 1)
 )

 (princ "initset loaded")
 (princ)
);;;加上这个右括号提示语法错误,去掉则提示输入的列表有缺陷



DCL代码如下:
--------------------------------------------------------------------------------

dcl-settings: default-dcl-settings {audit-level=3;}
init: dialog {aspect-ratio=0;
labe1=/*MSG1*/ "初始化";
:cluster {:cluster {layout=vertical;
:edit-box {key="edit-size";
allow-accept=true;
labe1="图幅";edit-width=6;
fixed-width=true;}: list-box {
key="list-size"; width=16;
fixed-width=true; allow-accept=true;}}
:cluster {layout=vertical;
:edit-box {key="edit-scale";
labe1=/*MSG20*/ "比例";
edit-width=6; fixed-width=true;}
: list-box {key="list-scale";
width=14; allow-accept=true;}}
:cluster {layout=vertical;
:boxed-radio-column {laybe1="装订线";

key="edeg"; : radio-button {
labe1="有"; value="1"; key="e-0";}
: radio-button {labe1="无"; key="e-1";}}
: boxed-radio-column{
labe1="图纸布置"; key="layout";
: radio-button {labe1="横置";
value="1"; key="1-0";} : radio-button {
labe1="纵置"; key="1-1";} }
: boxed-radio-column {
labe1="标题栏"; key="style";
: radio-button {labe1="格式 1";
value="1"; key="st-0";}
: radio-button {labe1="格式2";
key="st-1"; }}}}ok-cancel;}
define : dialog {
labe1="自定义"; initial-focus="b";
: cluster {: cluster {layout=vertical;
: edit-box {key="b"; labe1="B";
edit-width=10; fixed-width=true;}
: edit-box {key="1"; labe1="L";
edit-width=10; fixed-width=true;}
: edit-box {key="a"; labe1="a";
edit-width=10; fixed-width=true;}
: edit-box {key="c"; allow-accept=true;
labe1="c"; edit-width=10;
fixed-width=true;}}: image {key="image";
width=25; eight=10;}} ok-cancel;}
-----------------------------------------------------------------
发表于 2008-2-20 14:47 | 显示全部楼层
本帖最后由 作者 于 2008-2-20 14:55:53 编辑

菜鸟来回答

发现两个错误:

1:

LSP代码如下:
---------------------------------------------------------------------------------------
(defun c:initset ()
 (setq flag 0)
 (setq dcl-id (load-dialog "init.dcl"))
 (if (not (new-dialog "init" dcl-id)) (exit)) ;;begin if

红色为缺少的闭括号

2:

(defun sett(x y a c name scale tfb1)
     (setq 1 (strlen scale))
         (setq n (substr scale 1 1))
     (if (> n "1")
         (progn
             (setq 11 (-1 2))
      (setq scale1 (/1.0 (atof (substr scale 1 11))))
   )

数字不可设为变量

 楼主| 发表于 2008-2-20 15:18 | 显示全部楼层

谢楼上,修改2处后仍不能解决问题,头疼

发表于 2008-2-20 16:11 | 显示全部楼层
本帖最后由 作者 于 2008-3-3 15:25:04 编辑

试下:
  1. (defun c:initset ()
  2. (setq flag 0)
  3. (setq dcl-id (load_dialog "init.dcl"))
  4. (if (not (new_dialog "init" dcl-id)) (exit))
  5. (action_tile "list-size" "(list-size-cb $value)")
  6. (action_tile "list-scale" "(scal-list-cb $value)")
  7. (action_tile "accept" "(scal-accept-cb)")
  8. (setq lisca' ("1:1" "1:1.5" "1:2" "1:2.5" "1:3" "1:4" "1:5" "2:1" "2.5:1" "3:1" "4:1" "5:1"))
  9. (start_list "list-scale")
  10. (mapcar' add_list lisca)
  11. (end_list)
  12. (set_tile "edit-scale" "1:1")
  13. (setq lisize' ("A0 1189X841" "A1 841X594" "A2 594X420" "A3 420X297" "A4 210X297" "A5 210X148" "user用户自定义"))
  14. (start_list "list-size")
  15. (mapcar' add-list lisize)
  16. (end_list)
  17. (set_tile "edit-size" "A0")
  18. (start_dialog)
  19. (unload_dialog dcl-id)
  20. (grclear)
  21. (if (= flag 0) (quit))
  22. (sett x1 y1 a c name scale tfb)
  23. )
  24. (defun scal-list-cb(scale-v) ; 比例对应回调函数
  25.   (set_tile "edit-scale" (setq tu (nth (atoi scale-v) lisca)))
  26. )
  27. (defun list-size-cb(tub1) ; 图幅对应回调函数
  28. (cond
  29.   ((= tub1 "0") (mapcar 'set' '(tu1 x1 y1 c) '("A0" 1189 841 10)))
  30.   ((= tub1 "1") (mapcar 'set' '(tu1 x1 y1 c) '("A1" 841 594 10)))
  31.   ((= tub1 "2") (mapcar 'set' '(tu1 x1 y1 c) '("A2" 594 420 10)))
  32.   ((= tub1 "3") (mapcar 'set' '(tu1 x1 y1 c) '("A3" 420 297 10)))
  33.   ((= tub1 "4") (mapcar 'set' '(tu1 x1 y1 c) '("A4" 210 297 5)))
  34.   ((= tub1 "5") (mapcar 'set' '(tu1 x1 y1 c) '("A5" 210 148 5)))
  35.   ((= tub1 "6") (setq tu1 "user") (define))
  36. )
  37. (set-tile "edit-size" tu1)
  38. )
  39. (defun scal-accept-cb(); OK对应回调函数
  40. (setq scale (get_tile "edit-scale"))
  41. (setq name (get_tile "st-0"))
  42. (setq tufb (get_tile "edit-size"))
  43. (setq tfb (get_tile "1-0"))
  44. (setq ede (get_tile "e-0"))
  45. (if (= ede "1") (setq a 25) (setq a 10))
  46. (setq flag 1) (done_dialog 1)
  47. )
  48. (defun sett(x y a c name scale tfb1)
  49. (setq l (strlen scale))
  50. (setq n (substr scale 1 1))
  51. (if (> n "1") (progn
  52.   (setq ll (-1 2))
  53.   (setq scale1 (/1.0 (atof (substr scale 1 11))))
  54. )
  55.   (setq scale1 (atof (substr scale 3)))
  56. )
  57. (setq x (* x scale1)) ;图幅大小
  58. (setq y (* y scale1))
  59. (setq c (* scale1))
  60. (setq a (* a scale1))
  61. (if (/= tfb1 "1")  ;设置图纸方式
  62.   (setq t x x y y t)
  63. )
  64. (setvar "cmdecho" 0)  ;设置图层线型和颜色
  65. (command "linetype" "1" "center" "acad"\r "1" "hidden" "acad" \r "1" "phantom" \r \r)
  66. (setq lay "dimension, linehidden, linephantom, line-center, linesection, line-thin, part")
  67. (command "layer" "n" lay "c" "1" "linehidden" "c" "4" "dimension" "c" "5" "linephantom" "c" "5" "line-center" "c" "3" "linesection" "c" "2" "line-thin" "1" "center" "line-center" "1" "hidden" "linehidden" "1" "phantom" "linephantom" \r \r)
  68. (setq 1t (* 8 scale1)) (command "ltscale" 1t)
  69. (setq pt1 (list 0 0)); 绘制图框
  70. (setq pt2 (list x y))
  71. (setq pt3 (list x 0))
  72. (setq pt4 (list 0 y))
  73. (setq pt5 (list a c))
  74. (setq pt6 (list (- x c) (- y c)))
  75. (setq pt7 (list (- x c) c))
  76. (setq pt8 (list a (-y c)))
  77. (command "layer" "s" "line-thin" \r \r)
  78. (command "line" pt1 pt3 pt2 pt4 "c")
  79. (command "layer" "s" "part" \r \r)
  80. (command "line" pt5 pt7 pt6 pt8 "c")
  81. (command "zoom" "a")
  82.      ;选择标题栏形式TAB1,TAB2是已定义好的标题栏块
  83. (if (=name "1")
  84.   (setq name1 "tab1")
  85.   (setq name1 "tab2")
  86. )
  87. (setq r1 0)
  88. (setq pt7 (list (- x c) c))
  89. (command "insert" name1 pt7 scale1 scale1 r1)
  90. (setq li (* scale1 7))   ;尺寸标注初始化
  91. (setq se (* scale1 3.5))
  92. (setq xe (* scale1 2))
  93. (setq xt (* scale1 3.2))
  94. (setvar "dimclrd" 4)
  95. (setvar "dimclre" 4)
  96. (setvar "dimclrt" 7)
  97. (command "dim" "dimtof1" "1")
  98. (command "dimdli" li)
  99. (command "dimase" se)
  100. (command "exit")
  101. (setvar "dimexe" xe)
  102. (setvar "dimse1" 0)
  103. (setvar "dimse2" 0)
  104. (setvar "dimtxt" xt)
  105. (setvar "dimtfac" 0.5)
  106. (setvar "dimtix" 1)
  107. (setvar "dimsoxd" 0)
  108. (setvar "dimtad" 1)
  109. (setvar "dimtih" 0)
  110. (setvar "dimtoh" 0)
  111. (setvar "dimasz" xt)
  112. (setvar "cmdecho" 1)
  113. )
  114. (defun define ()  ;自定义图幅函数
  115. (setq dc1-id (load_dialog "init.dc1"))
  116. (new_dialog "define" dcl-id)
  117. (action_tile "accept" "(ok-cb)")
  118. (setq x2 (dimx_tile "image"))
  119. (setq y2 (dimy_tile "image"))
  120. (start_image "image")
  121. (fill_image 0 0 x2 y2-1)
  122. (silde_image 0 0 x2 y2 "init.sld")
  123. (end_image)
  124. (start_dialog)
  125. (unload_dialog dc1-id)
  126. )
  127. (defun ok-cb ()   ;自定义图幅OK回调函数
  128. (setq y1 (atof (get-tile "b")))
  129. (setq x1 (atof (get-tile "1")))
  130. (setq a (atof (get-tile "a")))
  131. (setq c (atof (get-tile "c")))
  132. (setq flag 1)
  133. (done-dialog 1)
  134. )
  135. (princ "initset loaded")
  136. (princ)
 楼主| 发表于 2008-2-21 11:42 | 显示全部楼层
ZZXXQQ版主,再试试
发表于 2008-3-3 14:39 | 显示全部楼层

 (setq dcl-id (load-dialog "init.dcl"))
 (if (not (new-dialog "init" dcl-id) (exit)) ;;begin if
     (action-tile "list-size" "(list-size-cb $value)")
     (action-tile "list-scale" "(scal-list-cb $value)")
     (action-tile "accept" "(scal-accept-cb)")
     (setq lisca' ("1:1" "1:1.5" "1:2" "1:2.5" "1:3" "1:4" "1:5" "2:1" "2.5:1" "3:1" "4:1" "5:1"))
     (start-list "list-scale")
     (mapcar' add_list lisca)
     (end-list)
     (set-tile "edit-scale" "1:1")
     (setq lisize' ("A0 1189X841" "A1 841X594" "A2 594X420" "A3 420X297" "A4 210X297" "A5 210X148" "user用户自定义"))
     (start-list "list-size")
     (mapcar' add-list lisize)
     (end-list)
     (set-tile "edit-size" "A0")
     (start-dialog)
     (unload-dialog dcl-id)
     (grclear)
     (if (=flag 0)
         (quit)
     )
     (sett x1 y1 a c name scale tfb)
   ) ;;end if

-----------------------------------------

函数写错了比如action-tile应该写成action_tile,set-tile应该写成set_tile

评分

参与人数 1明经币 +10 贡献 +5 激情 +5 收起 理由
ZZXXQQ + 10 + 5 + 5 【好评】表扬一下

查看全部评分

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

本版积分规则

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

GMT+8, 2024-5-17 10:58 , Processed in 0.337653 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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