cad二次开发,用lisp语言,image里面没有图像图形
本意效果
实际效果
DCL代码
dia8a:dialog{ label="图像辅助(参数设计)范例"; :row{ :boxed_radio_column{ label="设计样式"; :radio_button{label="L基本型"; key="rb1";} :radio_button{label="L+圆型";key="rb2";} :radio_button{label="L+双圆型";key="rb3";} :radio_button{label="L+弧型";key="rb4";}} :image{ key="kimage"; color=-2; width=30; aspect_radio=0.66; }} :row{ :edit_box{label="宽度ww";key="kww";} :edit_box{label="高度hh";key="khh";}}spacer_1;ok_cancel;}
以上是DCL代码
lisp的代码
(defun c:dia8a() (setvar "cmdecho" 0) (dcl_dia8a) (prin1) )(defun dcl_dia8a() (setq dcl_id (load_dialog "f:\zml")) (new_dialog "dia8a" dcl_id) (sub_rb1) (set_tile "rb1" "1") (set_tile "kww" "100") (set_tile "khh" "100") (action_tile "rb1" "(sub_rb1)") (action_tile "rb2" "(sub_rb2)") (action_tile "rb3" "(sub_rb3)") (action_tile "rb4" "(sub_rb4)") (action_tile "accept" "(ok_dia8a)(done_dialog 1)") (setq dd (start_dialog)) (if (= dd 1)(draw_dia8a)))
(defun sub_rb1() (setq ddtype 1) (show_sld "kimage" "dia8a1") ) (defun sub_rb2() (setq ddtype 2) (show_sld "kimage" "dia8a2") ) (defun sub_rb3() (setq ddtype 3) (show_sld "kimage" "dia8a3") ) (defun sub_rb4() (setq ddtype 4) (show_sld "kimage" "dia8a4") ) (defun show_sld (key sld) (setq x (dimx_tile key)) (setq y (dimy_tile key)) (start_image key) (fill_image 0 0 x y -2) (slide_image 0 0 x y sld) (end_image) ) (defun ok_dia8a() (setq ww (atof (get_tile "kww"))) (setq hh (atof (get_tile "khh"))) ) (defun draw_dia8a() (setq pt1 (getpoint "左下角基准点:")) (setq pt2 (polar pt1 0 ww)) (setq pt3 (polar pt2 (/ pi 2) hh)) (setq pt4 (polar pt3 pi (* ww 0.5))) (setq pt5 (polar pt4 (* pi 1.5)(* hh 0.5))) (setq pt6 (polar pt5 pi (* ww 0.5))) (cond ((= ddtype 1)(command "pline" pt1 pt2 pt3 pt4 pt5 pt6 "c")) ((= ddtype 2)(command "pline" pt6 pt1 pt2 pt3 pt4 "")(command "circle" "2p" pt4 pt6)) ((= ddtype 3)(command "pline" pt1 pt2 pt3 "")(command "pline" pt4 pt5 pt6 "")(command "circle" "2p" pt3 pt4 )(command "circle" "2p" pt6 pt1 )) ((= ddtype 4)(command "pline" pt1 pt2 pt3 pt4 "a" "a" -180 pt6 "l" "c")) ))
可以在CAD里面画出图形,但是image里面显示不出预览。 展开
问题出在load_dialog处,我已经修改好了。
你需要把存放DCL和SLD文件的文件夹加入到搜索路径中。我都放在E:\TEST中,所以增加了下面的路径。
如果解决了问题,请务必设为【采纳回答】哦。
(defun c:dia8a ()
(setvar "cmdecho" 0)
(dcl_dia8a)
(prin1)
)
(defun dcl_dia8a ()
(setq dcl_id (load_dialog "dia8a.dcl"))
(if (not (new_dialog "dia8a" dcl_id)) (exit))
(new_dialog "dia8a" dcl_id)
(sub_rb1)
(set_tile "rb1" "1")
(set_tile "kww" "100")
(set_tile "khh" "100")
(action_tile "rb1" "(sub_rb1)")
(action_tile "rb2" "(sub_rb2)")
(action_tile "rb3" "(sub_rb3)")
(action_tile "rb4" "(sub_rb4)")
(action_tile "accept" "(ok_dia8a)(done_dialog 1)")
(setq dd (start_dialog))
(if (= dd 1)
(draw_dia8a)
)
)
(defun sub_rb1 ()
(setq ddtype 1)
(show_sld "kimage" "dia8a1")
)
(defun sub_rb2 ()
(setq ddtype 2)
(show_sld "kimage" "dia8a2")
)
(defun sub_rb3 ()
(setq ddtype 3)
(show_sld "kimage" "dia8a3")
)
(defun sub_rb4 ()
(setq ddtype 4)
(show_sld "kimage" "dia8a4")
)
(defun show_sld (key sld)
(setq x (dimx_tile key))
(setq y (dimy_tile key))
(start_image key)
(fill_image 0 0 x y -2)
(slide_image 0 0 x y sld)
(end_image)
)
(defun ok_dia8a ()
(setq ww (atof (get_tile "kww")))
(setq hh (atof (get_tile "khh")))
)
(defun draw_dia8a ()
(setq pt1 (getpoint "左下角基准点:"))
(setq pt2 (polar pt1 0 ww))
(setq pt3 (polar pt2 (/ pi 2) hh))
(setq pt4 (polar pt3 pi (* ww 0.5)))
(setq pt5 (polar pt4 (* pi 1.5) (* hh 0.5)))
(setq pt6 (polar pt5 pi (* ww 0.5)))
(cond ((= ddtype 1) (command "pline" pt1 pt2 pt3 pt4 pt5 pt6 "c"))
((= ddtype 2)
(command "pline" pt6 pt1 pt2 pt3 pt4 "")
(command "circle" "2p" pt4 pt6)
)
((= ddtype 3)
(command "pline" pt1 pt2 pt3 "")
(command "pline" pt4 pt5 pt6 "")
(command "circle" "2p" pt3 pt4)
(command "circle" "2p" pt6 pt1)
)
((= ddtype 4)
(command "pline" pt1 pt2 pt3 pt4 "a" "a" -180 pt6 "l" "c")
)
)
)
成功了,真是太感谢了。我还有1个问题,1.假如我在E盘里建一个名字为“ABC”的文件夹,把每个幻灯片文件放在里面,在执行(show_sld "kimage" "E:\ABC\dia8a1.dcl")时没有DCL对话框出现。只有放在D,E等盘的里面才能出现DCL对话框并执行。这里面是不是有什么知识点?
DCL只有放在CAD的搜索路径下才可以show出来。
sld文件也一样需要放在搜索路径下。可以不需要指定路径,量需要放搜索路径下。