请教用lisp调用DCL单选键值后,程序无法正常运行。
一下是程序:(defun c:aa()
(setq cmdmode (getvar "cmdecho"))
(setvar "cmdecho" 0)
(if (= (tblsearch "layer" "0_RDCAD") nil)
(command "layer" "n" "0_RDCAD" "c" "2" "0_RDCAD" "")
)
(if (= (tblsearch "layer" "1_RDCAD") nil)
(command "layer" "n" "1_RDCAD" "c" "3" "1_RDCAD" "")
)
(if (= (tblsearch "layer" "2_RDCAD") nil)
(command "layer" "n" "2_RDCAD" "c" "1" "2_RDCAD" "")
)
(if (= (tblsearch "layer" "3_RDCAD") nil)
(command "layer" "n" "3_RDCAD" "c" "4" "3_RDCAD" "")
)
(if (= (tblsearch "layer" "4_RDCAD") nil)
(command "layer" "n" "4_RDCAD" "c" "7" "4_RDCAD" "")
)
(dcl_ganlu)
(prin1)
)
(defun dcl_ganlu()
(setq dcl_id (load_dialog "gan.dcl"))
(new_dialog "NextSetting" dcl_id)
(def_ganlu)
(action_tile "bilihuizhi" "(setq ddtype 1)")
(action_tile "dengjuhuizhi" "(setq ddtype 2)")
(action_tile "xinjian" "(setq ddtype 3)")
(action_tile "yuanyou" "(setq ddtype 4)")
(action_tile "chaichu" "(setq ddtype 5)")
(action_tile "accept" "(ok_bili)")
(setq dd (start_dialog))
(if (= dd 1)
(draw_ganlu)
)
(unload_dialog dcl_id)
)
(defun def_ganlu()
(if (= bl_draw nil)
(set_tile "bili_draw" "4000")
(set_tile "bili_draw" (rtos bl_draw))
)
)
(defun ok_bili()
(setq bl_draw (atof (get_tile "bili_draw")))
(done_dialog 1)
)
(DEFUN draw_ganlu ()
(setq ls 2.25 ;设定直线上面的字偏离直线的距离为ls
zg 2.5 ;设定字高zg
r 1.5) ;电杆半径
(command "-style" "Standard" "" 0 "" "" "" "" "") ;切换到默认的字体
(graphscr) ;切换到图形窗口
(setq oce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq bl bl_draw
;(setq bl (getint "\n请输入比例<推荐4000>,1:")
p1 (getpoint "\n杆路的起点:")
)
(setq osm (getvar "osmode"));储存对象捕捉的系统变量
(setvar "osmode" 0) ;关闭对象捕捉
(while (setq a1 (getangle p1 "\n杆路的方向<右键退出/Esc退出>:"))
(while (setq len (getdist "\n请输入杆距<米>:"))
(while ((= ddtype 1) (SETQ d (/ (* len 1000) bl))))
(while ((= ddtype 2) (SETQ d 15)))
;(setqd (SETQ d 15))
; (setqd (/ (* len 1000) bl))
(setq
p2 (polar p1 a1 d) ;计算p2的坐标
p11 (polar P1 a1 r)
p22 (polar p1 a1 (- d r))
p3 (list (/ (+ (car p1) (car p2)) 2.0) (/ (+ (cadr p1) (cadr p2)) 2.0)) ;计算p1p2的中点p3的坐标
)
(PROGN
(cond ((= ddtype 3) (command "layer" "s" "1_RDCAD" "")
(command "pline" p11 "w" 0.5 0.5 p22 "")
(command ".circle" p2 r))
((= ddtype 4) (command "layer" "s" "0_RDCAD" "")
(command "pline" p11 "w" 0.25 0.25 p22 "")
(command ".circle" p2 r))
((= ddtype 5) (command "layer" "s" "3_RDCAD" "")
(command "pline" p11 "w" 0.2 0.2 p22 "")
(command ".circle" p2 r))
))
; (command ".line" p11 p22 "")
; (command ".circle" p2 r)
(if (and(> a1 (* pi 0.5))(< a1 (* pi 1.5)))
(setq a2 (angle p2 p1))
(setq a2 a1)
)
(setq
p5 (polar p3 (+ a2 (/ pi 2)) ls) ;计算直线上面的文字位置
)
(command "layer" "s" "0" "")
(command ".text" "m" p5 zg (/ (* a2 180) pi) (rtos len 2 1)) ;以中央对齐的方式写直线上面的字:米
(setq p1 p2)
)
)
(setvar "osmode" osm)
(setvar "cmdecho" oce)
(princ)
)
一下是DCL文件:
NextSetting : dialog{
label = "杆路绘制设置";
:row{
:boxed_row{
label="间距绘制方式";
:radio_column{
key="ratio1";
:radio_button{label="按比例绘制"; key="bilihuizhi";}
:radio_button{label="等间距绘制"; key="dengjuhuizhi";}
spacer_1;
spacer_1;
}
:column{
:edit_box{label="比例 1:";key="bili_draw";edit_width=6;}
:text{label="15"; key="valRatio2";}
spacer_1;
spacer_1;
}
}
:boxed_column{
label="布放类别";
:radio_column{
:radio_button{label="新建"; key="xinjian";}
:radio_button{label="原有"; key="yuanyou";}
:radio_button{label="拆除"; key="chaichu";}
}
}
}
ok_cancel;
}
现在的问题是:
(while ((= ddtype 1) (SETQ d (/ (* len 1000) bl))))
(while ((= ddtype 2) (SETQ d 15)))
;(setqd (SETQ d 15))
; (setqd (/ (* len 1000) bl))
我把这个改为(setqd (SETQ d 15))或者(setqd (/ (* len 1000) bl))后程序可以运行,但是加了选择后程序就无法运行了。请教这个程序该怎么修改。
(defun c:aa()
(setq cmdmode (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "layer" "m" "0_RDCAD" "c" "2" "" "")
(command "layer" "m" "1_RDCAD" "c" "3" "" "")
(command "layer" "m" "2_RDCAD" "c" "1" "" "")
(command "layer" "m" "3_RDCAD" "c" "4" "" "")
(command "layer" "m" "4_RDCAD" "c" "7" "" "")
(dcl_ganlu)
(prin1)
)
(defun dcl_ganlu()
(if (> (setq dcl_id (load_dialog "gan.dcl")) 0) (progn
(if (new_dialog "NextSetting" dcl_id) (progn
(def_ganlu)
(action_tile "bilihuizhi" "(setq ddtype 1)")
(action_tile "dengjuhuizhi" "(setq ddtype 2)")
(action_tile "xinjian" "(setq ddtype 3)")
(action_tile "yuanyou" "(setq ddtype 4)")
(action_tile "chaichu" "(setq ddtype 5)")
(action_tile "accept" "(ok_bili)(done_dialog 1)")
(setq dd (start_dialog))
)
(princ "\n无法显示对话框!")
)
(unload_dialog dcl_id)
)
(princ "\n无法加载对话框!")
)
(if (= dd 1) (draw_ganlu))
)
(defun def_ganlu ()
(set_tile "bili_draw" (if bl_draw (rtos bl_draw 2) "4000"))
)
(defun ok_bili ()
(setq bl_draw (atof (get_tile "bili_draw")))
)
(defun draw_ganlu ()
(setq ls 2.25 ;设定直线上面的字偏离直线的距离为ls
zg 2.5 ;设定字高zg
r 1.5) ;电杆半径
(setvar "TEXTSTYLE" "Standard") ;切换到默认的字体
(graphscr) ;切换到图形窗口
(setq oce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq bl bl_draw
;(setq bl (getint "\n请输入比例<推荐4000>,1:")
p1 (getpoint "\n杆路的起点:")
)
(setq osm (getvar "osmode"));储存对象捕捉的系统变量
(setvar "osmode" 0) ;关闭对象捕捉
(while (setq a1 (getangle p1 "\n杆路的方向<右键退出/Esc退出>:"))
(while (setq len (getdist "\n请输入杆距<米>:"))
(if (= ddtype 1) (SETQ d (/ (* len 1000) bl)))
(if (= ddtype 2) (SETQ d 15))
;(setq d (SETQ d 15))
; (setq d (/ (* len 1000) bl))
(setq p2 (polar p1 a1 d) ;计算p2的坐标
p11 (polar P1 a1 r)
p22 (polar p1 a1 (- d r))
p3 (list (/ (+ (car p1) (car p2)) 2.0) (/ (+ (cadr p1) (cadr p2)) 2.0)) ;计算p1p2的中点p3的坐标
)
(cond
((= ddtype 3)
(command "layer" "s" "1_RDCAD" "")
(command "pline" p11 "w" 0.5 0.5 p22 "")
(command ".circle" p2 r)
)
((= ddtype 4)
(command "layer" "s" "0_RDCAD" "")
(command "pline" p11 "w" 0.25 0.25 p22 "")
(command ".circle" p2 r)
)
((= ddtype 5)
(command "layer" "s" "3_RDCAD" "")
(command "pline" p11 "w" 0.2 0.2 p22 "")
(command ".circle" p2 r)
)
)
; (command ".line" p11 p22 "")
; (command ".circle" p2 r)
(if (< (* pi 0.5) a1 (* pi 1.5))
(setq a2 (angle p2 p1))
(setq a2 a1)
)
(setq p5 (polar p3 (+ a2 (/ pi 2)) ls)) ;计算直线上面的文字位置
(command "layer" "s" "0" "")
(command ".text" "m" p5 zg (/ (* a2 180) pi) (rtos len 2 1)) ;以中央对齐的方式写直线上面的字:米
(setq p1 p2)
)
)
(setvar "osmode" osm)
(setvar "cmdecho" oce)
(princ)
)
Z版,程序还是不行,提示: 错误: 参数类型错误: numberp: nil,把(if (= ddtype 1) (SETQ d (/ (* len 1000) bl)))和 (if (= ddtype 2) (SETQ d 15))这两行屏蔽掉改为(setq d (SETQ d 15))或者 (setq d (/ (* len 1000) bl)),程序就可以运行,不过只有对于的功能。
楼主也做通信的吗?哈哈 你这个程序做的有点死,比如杆子高度,电杆直径 rdhhb 发表于 2016-1-4 09:43
你这个程序做的有点死,比如杆子高度,电杆直径
你也是做通信的?你有好的程序发来用用呗。 发个图片给你看看
页:
[1]