本帖最后由 xxwz 于 2018-3-23 17:16 编辑
《AutoCAD程序设计魔法书》中16-4章节的例子,lsp和dcl文件见附件。
- (defun c:dia5b()
- (setvar "CMDECHO" 0)
- (dcl_dia5b)
- (prin1)
- )
- (defun dcl_dia5b()
- (setq dcl_id (load_dialog "dia5b"))
- (new_dialog "dia5b" dcl_id)
- (set_tile "kww" "50")
- (set_tile "khh" "50")
- (action_tile "bb1" "(get_ww_hh) (done_dialog 1)")
- (action_tile "bb2" "(get_ww_hh) (done_dialog 2)")
- (action_tile "bb3" "(get_ww_hh) (done_dialog 3)")
- (setq dd (start_dialog))
- (cond ((= dd 1) (c:dia5b1))
- ((= dd 2) (c:dia5b2))
- ((= dd 3) (c:dia5b3))
- (t (alert "未完成任何动作!!!"))
- )
- )
- (defun get_ww_hh() ;取得对话框的ww与hh值
- (setq ww (atof (get_tile "kww")))
- (setq hh (atof (get_tile "khh")))
- )
- (defun c:dia5b1() ;L型主程序
- (setvar "CMDECHO" 0)
- (get_input_data)
- (command "PLINE" p1 p2 p3 pm34 pm pm14 "c")
- (prin1)
- )
- (defun c:dia5b2() ;X型主程序
- (setvar "CMDECHO" 0)
- (get_input_data)
- (command "PLINE" p1 p2 p3 p4 "c")
- (command "LINE" p1 p3 "")
- (command "LINE" p2 p4 "")
- (prin1)
- )
- (defun c:dia5b3() ;漏斗型主程序
- (setvar "CMDECHO" 0)
- (get_input_data)
- (command "PLINE" p1 p2 p4 p3 "c")
- (prin1)
- )
- (defun get_input_data() ;共同数据取得与处理子程序
- ;;;(setq ww (getreal "\n宽度WW:")) ;动作取消
- ;;;(setq hh (getreal "\n高度HH:")) ;动作取消
- (setq p1 (getpoint "\n插入点:"))
- (setq p2 (polar p1 0 ww))
- (setq p3 (polar p2 (* pi 0.5) hh))
- (setq p4 (polar p3 pi ww))
- (setq pm (inters p1 p3 p2 p4))
- (setq pm12 (polar p1 0 (* ww 0.5)))
- (setq pm34 (polar p3 pi (* ww 0.5)))
- (setq pm23 (polar p2 (* pi 0.5) (* hh 0.5)))
- (setq pm14 (polar p1 (* pi 0.5) (* hh 0.5)))
- )
- /*★★★★★ListDCL @ fsxm.mjtd.com★★★★★*/
- dia5b:dialog {
- label = "按钮测试范例" ;
- :boxed_row {
- label = "图形尺寸" ;
- :edit_box {
- edit_width = 8 ;
- key = "kww" ;
- label = "宽度WW" ;
- }
- :edit_box {
- edit_width = 8 ;
- key = "khh" ;
- label = "高度HH" ;
- }
- }
- :button {
- key = "bb1" ;
- label = "绘制DIA5B1→L 型" ;
- }
- :button {
- key = "bb2" ;
- label = "绘制DIA5B2→X 型" ;
- }
- :button {
- key = "bb3" ;
- label = "绘制DIA5B3→漏洞型" ;
- }
- spacer_1;
- cancel_button;
- }
程序运行后,不出现对话框,直接提示"未完成任何动作!!!"。
请大神帮看看什么原因,谢谢!
祝好!
|