feng83 发表于 2014-5-5 21:06:01

初学DCL,遇到的问题,请教下

本帖最后由 feng83 于 2014-5-5 21:09 编辑

初学DCL,按教程写了如下代码,老是报错,把(action_tile "accept" "(S_RECT)(done_dialog)")改成(action_tile "accept" "(S_RECT)")就可以了,不太明白,看了论坛的很多源代码,都有带(done_dialog)终止对话框,请教高手解答下
环境AUTO CAD 2007,win 7系统

(DEFUN C:RECT4 ()
(SETQ DCL_ID (LOAD_DIALOG "c:/RECT4.DCL"))
(NEW_DIALOG "RECT4" DCL_ID)
(SET_TILE "rect_w" "50")
(SET_TILE "rect_h" "20")
(action_tile "accept" "(S_RECT)(done_dialog)")
(START_DIALOG)(UNLOAD_DIALOG)
(SETQ PT_0 (GETPOINT "\n 选择一个点 : "))
(SETQ PT_1 (POLAR PT_0 0 TMP_W))
(SETQ PT_2 (POLAR PT_1 (/ PI 2 ) TMP_H))
(SETQ PT_3 (POLAR PT_2PI TMP_W))
(COMMAND "PLINE" PT_0 PT_1 PT_2 PT_3 "C")
(PRINC)
)
(DEFUN S_RECT ()
   (SETQ TMP_W (ABS (ATOF (GET_TILE "rect_w"))))
   (SETQ TMP_H (ABS (ATOF (GET_TILE "rect_h"))))
)

feng83 发表于 2014-5-5 21:15:32

另外也请帮忙看下下面的代码错在那了,想弹出一个对话框,点相应按钮执行相应命令(命令太多了),运行以下程序,弹出对话框,就不能动了
(DEFUN C:ssss ()
(SETQ DCL_ID (LOAD_DIALOG "c:/ssss.DCL"))
(NEW_DIALOG "ssss" DCL_ID)
(action_tile "cancel""(done_dialog)")
(action_tile "ml_01""(sq)(done_dialog)")
(action_tile "ml_02""(sw)(done_dialog)")
(START_DIALOG)(UNLOAD_DIALOG DCL_ID)
(PRINC)
)
(defun sq ( / oce a1 a2 a3 i)
(setq oce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(graphscr)
(prompt "\n 选择需要锁的对象:")
(setq a1(ssget))
(if a1
    (progn
      (setq i 0)
      (repeat (sslength a1)
      (setq a3 (ssname a1 i))
      (setq a2 (cdr (assoc 8 (entget a3))))
      (command "LAYER" "lo" a2"")
      (setq i (1+ i))
      )
      (princ a2)
    ))
(setvar "cmdecho" oce)
(princ)
)
(defun sw( / oce a1 a2 a3 i)
(setq oce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(graphscr)
(prompt "\n 选择需要解锁的对象:")
(setq a1(ssget))
(if a1
    (progn
      (setq i 0)
      (repeat (sslength a1)
      (setq a3 (ssname a1 i))
      (setq a2 (cdr (assoc 8 (entget a3))))
      (command "LAYER" "u" a2"")
      (setq i (1+ i))
      )
      (princ a2)
    ))
(setvar "cmdecho" oce)
(princ)
)

ZZXXQQ 发表于 2014-5-6 08:13:56

(DEFUN C:RECT4 ()
(if (> (SETQ DCL_ID (LOAD_DIALOG "c:/RECT4.DCL")) 0) (progn
(if (NEW_DIALOG "RECT4" DCL_ID) (progn
   (SET_TILE "rect_w" "50")
   (SET_TILE "rect_h" "20")
   (action_tile "accept" "(S_RECT)(done_dialog 1)")
   (action_tile "cancel" "(done_dialog 0)")
   (setq re (start_dialog))
)
   (princ "\n无法显示对话框!")
)
(UNLOAD_DIALOG DCL_ID)
)
(princ "\n无法加载对话框!")
)
(if (= re 1) (progn
(SETQ PT_0 (GETPOINT "\n 选择一个点 : "))
(setq pt_2 (mapcar '+ (list tmp_w tmp_h)))
;(SETQ PT_1 (POLAR PT_0 0 TMP_W))
;(SETQ PT_2 (POLAR PT_1 (/ PI 2 ) TMP_H))
;(SETQ PT_3 (POLAR PT_2PI TMP_W))
;(COMMAND "PLINE" PT_0 PT_1 PT_2 PT_3 "C")
(command "_.RECTANG" PT_0 pt_2)
))
(PRINC)
)
(DEFUN S_RECT ()
   (SETQ TMP_W (ABS (ATOF (GET_TILE "rect_w"))))
   (SETQ TMP_H (ABS (ATOF (GET_TILE "rect_h"))))
)

feng83 发表于 2014-5-6 21:49:31

ZZXXQQ 发表于 2014-5-6 08:13 static/image/common/back.gif


非常感谢Z版主抽空帮忙改写了代码,CAD有点问题不能测试你的代码,不过有几点疑问请教下:
1   (done_dialog ) 改成 (done_dialog 1) 是不是解决参数太少的问题或是说让done_dialog 终止后返回1?为什么把(action_tile "accept" "(S_RECT)(done_dialog)")改成(action_tile "accept" "(S_RECT)")就可以,终止对话框不写入应该是对话框关不掉,现在,不写反而好了,写反而不行
2加入IF和(UNLOAD_DIALOG DCL_ID)是不是解决对话框关不掉的问题

ZZXXQQ 发表于 2014-5-7 07:49:15

feng83 发表于 2014-5-6 21:49 static/image/common/back.gif
非常感谢Z版主抽空帮忙改写了代码,CAD有点问题不能测试你的代码,不过有几点疑问请教下:
1   (done_di ...

程序是按CAD自带的DCL改的,是标准格式,加入了错误处理。OpenDCL不会。
一般未退出DCL时CAD是不能使用COMMAND的。

feng83 发表于 2014-5-7 23:18:34

ZZXXQQ 发表于 2014-5-7 07:49 static/image/common/back.gif
程序是按CAD自带的DCL改的,是标准格式,加入了错误处理。OpenDCL不会。
一般未退出DCL时CAD是不能使用C ...
还是不行,,还是提示参数太少,将(done_dialog 1) 去掉就可以

feng83 发表于 2014-5-7 23:53:27

feng83 发表于 2014-5-7 23:18 static/image/common/back.gif
还是不行,,还是提示参数太少,将(done_dialog 1) 去掉就可以

CAD重装又可以了,不过在公司电脑上还是不行

ZZXXQQ 发表于 2014-5-8 08:00:08

(DEFUN C:ssss ()
(if (> (SETQ DCL_ID (LOAD_DIALOG "c:/ssss.DCL")) 0) (progn
(setq re 4)
(while (> re 1)
   (if (NEW_DIALOG "ssss" DCL_ID) (progn
    (action_tile "ml_01" "(done_dialog 2)")
    (action_tile "ml_02" "(done_dialog 3)")
    (action_tile "accept" "(done_dialog 1)")
    (action_tile "cancel" "(done_dialog 0)")
    (setq re (START_DIALOG))
   )
    (princ "\n无法显示对话框!")
   )
   (cond
    ((= re 2) (sq))
    ((= re 3) (sw))
   )
)
(UNLOAD_DIALOG DCL_ID)
)
(princ "\n无法加载对话框!")
)
(PRINC)
)
(defun sq (/ a1 a2 i)
(setq oce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(graphscr)
(princ "\n选择需要锁的对象: ")
(if (setq a1(ssget)) (progn
    (setq i -1)
    (repeat (sslength a1)
   (setq a2 (cdr (assoc 8 (entget (ssname a1 (setq i (1+ i)))))))
   (command "LAYER" "lo" a2 "")
    )
    (princ a2)
   ))
(setvar "cmdecho" oce)
(princ)
)
(defun sw(/ a1 a2 i)
(setq oce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(graphscr)
(prompt "\n选择需要解锁的对象: ")
(if (setq a1(ssget)) (progn
(setq i -1)
(repeat (sslength a1)
   (setq a2 (cdr (assoc 8 (entget (ssname a1 (setq i (1+ i)))))))
   (command "LAYER" "u" a2"")
)
(princ a2)
))
(setvar "cmdecho" oce)
(princ)
)

feng83 发表于 2014-5-10 06:15:14

谢谢ZZXXQQ的回复,已解决了问题,再次感谢
页: [1]
查看完整版本: 初学DCL,遇到的问题,请教下