明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 744|回复: 0

[机械] 高手进!!!!

[复制链接]
发表于 2015-5-18 10:29 | 显示全部楼层 |阅读模式
做了个程序。画图中没办法屏幕取点。手动输入基点可以。程序只写了第一张图函数。和第三张图函数。
基点按钮  start
X轴坐标编辑框  start_x
Y轴坐标编辑框  start_y
基点主程序都标注为红色,如下
对话框程序

zhudhk:dialog{
  label="轴结构CAD软件设计";
  :row{

  :column{
      :image_button{
        color=0;
        width=40;
        height=20;
        key="shaft_image";
        }
      :button{
        label="选择轴段";
        key="shaft_type";
        fixed_width=true;
        alignment=centered;
        }
      :boxed_radio_row{
          label="方向";
          key="direction";
          value="yuo";
             :radio_button{
               label="水平向右";
               key="alph_you";}
             :radio_button{
               label="水平向左";
               key="alph_zou";}
        }
   }
:column{
   :boxed_column{label="参数输入(单位:mm):";
       :row{
         :popup_list {
                    label="轴段类型     倒角";
                    key= "list_daoj";}
                   }
       :row{

         :edit_box{
           label="矩形轴段     长度";
           key="changd1";}
         :edit_box{
           label="直径";
           key="zhij1";}
           }
       :row{        
         :edit_box{
           label="梯形轴段     左径";
           key="zuoj";}
         :edit_box{
           label="右径";
           key="yuoj";}
           }
       :row{
         :popup_list {
                    label="齿轮轴段     模数";
                    key= "list_mosh";}         
         :edit_box{
           label="齿数";
           key="chish";}
           }

       :row{         
         :edit_box{
           label="螺纹轴段     长度";
           key="changd2";}
         :edit_box{
           label="直径d";
           key="zhij2";}
           }
       :row{
         :popup_list {
                    label="退刀槽段     长度";
                    key= "list_changd3";}
         :popup_list {
                    label="d-dg";
                    key= "list_zhij3";}         
           }               
           :row{
              :edit_box{
                 label="键槽轴段     距离";
                 key="juli";}
              :edit_box{
                 label="长度";
                 key="changd4";}            
               }
           :row{
               :popup_list {
                    label="宽度";
                    key= "list_kuand";}
               :popup_list {
                    label="轴深";
                    key= "list_zhoush";}              
               }
               }
spacer; spacer; spacer; spacer; spacer;

               :row{
                          :boxed_column{ label="基点:";
                          children_alignment=left;
                         
                          :edit_box{label="X轴座标:";
                                        key="start_x";
                                          edit_width=6;
                          }
                          :edit_box{label="Y轴座标:";
                                           key="start_y";
                                           edit_width=6;
                          }
                          :button{ label="鼠标点选";   
                                      key="pick_point";
                                      width=6;fixed_width=true;
                          }
                                       }
          :column{
spacer; spacer; spacer; spacer;
          :button {
                   label="绘制";
                   key="button_hz";
                   width=6;
                   fixed_width=true;
                   alignment=centered;
                     }
cancel_button;
                     
               }}

               }



    }}



    tuxiang:dialog{
    label="轴段图像选择";
    :row{
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang1";}
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang2";}
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang3";}
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang4";}
        }
    :row{
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang5";}
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang6";}
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang7";}
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang8";}
        }
    :row{
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang9";}
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang10";}
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang11";}
        :image_button{
            color=0;
            width=25;
            height=10;
            key="tuxiang12";}
        }
ok_cancel;


            }

主程序

(defun zjgsj ()
          (setq shaft_type 1 alph 0)
          (setq        ss  nil ss1 nil)
          (setq ss (ssadd))
         (setq ss1 (ssadd))
         (setq start (list 0.0 0.0 ))
         (setvar "cmdecho" 0)
         (command "ltscale" 5)
         (command "layer" "m" "draw" "c" "white" "" "")
         (command "layer" "m" "center"        "c" "red" "" "l" "center" "" "")
         (command "layer" "m" "dashed"        "c" "white" "" "l" "dashed" "" "")
         (command "osmode" "0")
  (setq wjlj "C:/Users/original_01/Desktop/毕业设计/")
         (shaft_start)
   (flist1)
  (action_tile "list_daoj" "(tqlist1)")
  (flist2)
  (action_tile "list_mosh" "(tqlist2)")
  (flist3)
  (action_tile "list_changd3" "(tqlist3)")
  (flist4)
  (action_tile "list_zhij3" "(tqlist4)")
  (flist5)
  (action_tile "list_kuand" "(tqlist5)")
  (flist6)  
  (action_tile "list_zhoush" "(tqlist6)")
         (while (< 0 what)
            (shaft_action)
               (cond
                      ((= what 2) (shaft_pick) (shaft_set))
                      ((= what 1) (shaft_draw))
                )
         )
         (unload_dialog aug)
         (setvar "cmdecho" 1)
)
;;;**********************主函数结束***********************************************

;;;/*初始化轴的对话框函数*/
(defun shaft_start ()
          (setq what 5)
          (setq aug (load_dialog (strcat wjlj "zjgsj.dcl")))
          (if (not (new_dialog "zhudhk" aug "" ))
            (exit)
          )

          (shaft_vslide "shaft_image" (strcat wjlj "tupian1") 0)
          (set_tile "start_x" (rtos (car start) 2 1))
          (set_tile "start_y" (rtos (cadr start) 2 1))
          (mode)

  (action_tile "alph_you" "(setq alph 0)")
  (action_tile "alph_zou" "(setq alph pi)")

)

;;;/*shaft_action()为控件动作函数*/
(defun shaft_action ()
          (action_tile "shaft_type" "(shaft_stype)")

          (action_tile "changd1" "(shaft_input)")
          (action_tile "zhij1" "(shaft_input)")
          (action_tile "zuoj" "(shaft_input)")
          (action_tile "yuoj" "(shaft_input)")
          (action_tile "chish" "(shaft_input)")
          (action_tile "changd2" "(shaft_input)")
          (action_tile "zhij2" "(shaft_input)")
          (action_tile "juli" "(shaft_input)")
          (action_tile "changd4" "(shaft_input)")


          (action_tile "list_daoj" "(shaft_input)")
          (action_tile "list_mosh" "(shaft_input)")
          (action_tile "list_changd3" "(shaft_input)")
          (action_tile "list_zhij3" "(shaft_input)")
          (action_tile "list_kuand" "(shaft_input)")
          (action_tile "list_zhoush" "(shaft_input)")

          (action_tile "pick_point" "(shaft_input) (done_dialog 2)")
          (action_tile "start_x" "(shaft_input)")
          (action_tile "start_y" "(shaft_input)")
          (action_tile "button_hz" "(shaft_input) (done_dialog 1)")




          (setq what (start_dialog))
)
;;;/*设定各控件状态的函数*/
(defun shaft_set ()
          (new_dialog "zhudhk" aug "" )
          (shaft_vslide
            "shaft_image" sldname
            ;(strcat (strcat wjlj "shaa") (itoa shaft_type))
            0
          )
          (mode)
          (set_tile "changd1" (rtos L1 2 1))
          (set_tile "zhij1" (rtos D1 2 1))
          (set_tile "zuoj" (rtos Dz 2 1))
          (set_tile "yuoj" (rtos Dy 2 1))
          (set_tile "chish" (rtos z 2 1))
          (set_tile "changd2" (rtos L2 2 1))
          (set_tile "zhij2" (rtos D2 2 1))
          (set_tile "juli" (rtos L 2 1))
          (set_tile "changd4" (rtos L4 2 1))

  (set_tile "list_daoj" (rtos C 2 1))
  (set_tile "list_mosh" (rtos m 2 1))
  (set_tile "list_changd3" (rtos L3 2 1))
  (set_tile "list_zhij3" (rtos D3 2 1))
  (set_tile "list_kuand" (rtos b 2 1))
  (set_tile "list_zhoush" (rtos h 2 1))


          (set_tile "start_x" (rtos (car start) 2 1))
          (set_tile "start_y" (rtos (cadr start) 2 1))
)
;;;/*设定各控件的可操作状态为enable(0)或disable(1)*/
(defun mode ()
          (mode_tile "changd1"  (if (or (= shaft_type 1) (= shaft_type 2)(= shaft_type 3)
                                        (= shaft_type 4)(= shaft_type 5) (= shaft_type 6)(= shaft_type 7) (= shaft_type 8))    0 1))
          (mode_tile "zhij1"     (if (or (= shaft_type 1) (= shaft_type 2)(= shaft_type 3) (= shaft_type 4)(= shaft_type 5) (= shaft_type 6))  0 1))
          (mode_tile "zuoj"    (if (= shaft_type 7)                        0 1))
          (mode_tile "yuoj"    (if (= shaft_type 7)                        0 1))
          (mode_tile "chish"    (if (= shaft_type 8)                       0 1))
          (mode_tile "changd2"     (if (or (= shaft_type 9) (= shaft_type 10))  0 1))
          (mode_tile "zhij2"     (if (or (= shaft_type 9) (= shaft_type 10))      0 1))
          (mode_tile "juli"    (if (or (= shaft_type 2) (= shaft_type 4)(= shaft_type 6))                        0 1))
          (mode_tile "changd4"    (if(or (= shaft_type 2) (= shaft_type 4)(= shaft_type 6))                        0 1))

          (mode_tile "list_daoj"     (if (or (= shaft_type 1) (= shaft_type 2)(= shaft_type 5) (= shaft_type 6)(= shaft_type 8) )  0 1))
          (mode_tile "list_mosh"    (if (= shaft_type 8)                       0 1))
          (mode_tile "list_changd3"     (if (or (= shaft_type 9) (= shaft_type 10))      0 1))
          (mode_tile "zhij3"     (if (or (= shaft_type 9) (= shaft_type 10))      0 1))
          (mode_tile "list_kuand"    (if (or (= shaft_type 2) (= shaft_type 4)(= shaft_type 6))                        0 1))
          (mode_tile "list_zhoush"    (if (or (= shaft_type 2) (= shaft_type 4)(= shaft_type 6))                        0 1))  
)
;;;/*在对话框上显示幻灯片的函数*/
(defun shaft_vslide (key s_name n / x y)
          (setq x (dimx_tile key))
          (setq y (dimy_tile key))
          (start_image key)
          (fill_image n 0 x y 0)
          (slide_image n 0 x y s_name)
          (end_image)
)
;;;/*选择轴段特征结构函数*/
(defun shaft_stype (/ what1)
          (if (not (new_dialog "tuxiang" aug "" ))
               (exit)
          )
          (fy1)
          (action_tile "tuxiang1" "(setq shaft_type 1)")
          (action_tile "tuxiang2" "(setq shaft_type 2)")
          (action_tile "tuxiang3" "(setq shaft_type 3)")
          (action_tile "tuxiang4" "(setq shaft_type 4)")
          (action_tile "tuxiang5" "(setq shaft_type 5)")
          (action_tile "tuxiang6" "(setq shaft_type 6)")
          (action_tile "tuxiang7" "(setq shaft_type 7)")
          (action_tile "tuxiang8" "(setq shaft_type 8)")
          (action_tile "tuxiang9" "(setq shaft_type 9)")
          (action_tile "tuxiang10" "(setq shaft_type 10)")
          (action_tile "accept"  "(done_dialog 0)")
          (setq what1 (start_dialog))

         (setq listsldname '("1"  "" "tupian1" "tupian2" "tupian3" "tupian4" "tupian5" "tupian6"
                              "tupian7" "tupian8" "tupian9" "tupian10"                              ))
          (setq sldname (strcat wjlj (nth shaft_type (cdr  listsldname))))
          (shaft_vslide "shaft_image"  sldname 0)
          (mode)

)
(defun fy1 ();显示轴段选择主对话框第一页

          (shaft_vslide "tuxiang1" (strcat wjlj "tupian1") 0)
          (shaft_vslide "tuxiang2" (strcat wjlj "tupian2") 0)
          (shaft_vslide "tuxiang3" (strcat wjlj "tupian3") 0)
          (shaft_vslide "tuxiang4" (strcat wjlj "tupian4") 0)
          (shaft_vslide "tuxiang5" (strcat wjlj "tupian5") 0)
          (shaft_vslide "tuxiang6" (strcat wjlj "tupian6") 0)
          (shaft_vslide "tuxiang7" (strcat wjlj "tupian7") 0)
          (shaft_vslide "tuxiang8" (strcat wjlj "tupian8") 0)
          (shaft_vslide "tuxiang9" (strcat wjlj "tupian9") 0)
          (shaft_vslide "tuxiang10" (strcat wjlj "tupian10") 0)

)

;;;/*初始化输入的数据的主调函数*/
(defun shaft_input ()
          (setq L1 (atof (get_tile "changd1")))
          (setq D1 (atof (get_tile "zhij1")))
          (setq Dz (atof (get_tile "zuoj")))
          (setq Dy (atof (get_tile "yuoj")))
          (setq z (atof (get_tile "chish")))
          (setq L2 (atof (get_tile "changd2")))
          (setq D2 (atof (get_tile "zhij2")))
          (setq L (atof (get_tile "juli")))
          (setq L4 (atof (get_tile "changd4")))

   (flist1)
  (action_tile "list_daoj" "(tqlist1)")
  (flist2)
  (action_tile "list_mosh" "(tqlist2)")
  (flist3)
  (action_tile "list_changd3" "(tqlist3)")
  (flist4)
  (action_tile "list_zhij3" "(tqlist4)")
  (flist5)
  (action_tile "list_kuand" "(tqlist5)")
  (flist6)  
  (action_tile "list_zhoush" "(tqlist6)")

          (setq        start (list (atof (get_tile "start_x")) (atof (get_tile "start_y")) ))
)




;;;/*从屏幕上获取轴的起始点的函数*/
(defun shaft_pick ()
          (command "snap" "1")
          (setq start (getpoint "\n 输入轴的起始点:"))
)
;;;/*调用绘图函数的主调函数*/
(defun shaft_draw ()
          (cond
            ((= shaft_type 1) (jxone))
            ((= shaft_type 2) (jxtwo))
            ((= shaft_type 3) (jxthree))
            ((= shaft_type 4) (jxfour))
            ((= shaft_type 5) (jxfive))
            ((= shaft_type 6) (jxsix))
            ((= shaft_type 7) (tixing))
            ((= shaft_type 8) (chilun))
            ((= shaft_type 9) (lwone))
            ((= shaft_type 10) (lwtwo))
          )
          (setq        shaft_type 1)(shaft_start)
)

(defun flist1 ()                                               ;向第一个倒角列表框中填内容
         (setq yyg1 '("0.2"  "0.4" "0.6"  "0.8" "1.0" "1.6" "2.0" "2.5"
                     "3.0" "4.0" "5.0" "6.0" "8.0" "10" "12"  "16"         ))
         (start_list "list_daoj")
         (mapcar 'add_list yyg1)
         (end_list)
)
(defun tqlist1 ()                                             

         (setq yyg2 '("0.2"  "0.4" "0.6"  "0.8" "1.0" "1.6" "2.0" "2.5"
                     "3.0" "4.0" "5.0" "6.0" "8.0" "10" "12"  "16" ))
         (setq fhyy2 (atoi (get_tile "list_daoj" )))
         (setq C  (nth fhyy2 yyg2 ))
)
(defun flist2 ()                                               ;向第二个模数列表框中填内容
         (setq yyg2 '("0.12"  "0.15" "0.2"  "0.25" "0.3" "0.4" "0.5" "0.6" "0.8" "1"
                     "1.25" "1.5" "2" "2.5" "3" "4" "5"  "6" "8" "10" "12" "16" "20" "25" "32" "40" "50"        ))
         (start_list "list_mosh")
         (mapcar 'add_list yyg2)
         (end_list)
)

(defun tqlist2 ()                                             

         (setq yyg2 '("0.12"  "0.15" "0.2"  "0.25" "0.3" "0.4" "0.5" "0.6" "0.8" "1"
                     "1.25" "1.5" "2" "2.5" "3" "4" "5"  "6" "8" "10" "12" "16" "20" "25" "32" "40" "50" ))
         (setq fhyy2 (atoi (get_tile "list_mosh" )))
         (setq m  (nth fhyy2 yyg2 ))
)
(defun flist3 ()                                               ;向第三个退刀槽长度列表框中填内容
         (setq yyg3 '("1.5"  "1.8" "2.1"  "2.25" "2.4" "3" "3.75" "4.5"
                     "5.25" "6" "7.5" "9" "10.5"  "12"  "13.5" "15" "17.5" "18"       ))
         (start_list "list_changd3")
         (mapcar 'add_list yyg3)
         (end_list)
)
(defun tqlist3 ()                                             

         (setq yyg3 '("1.5"  "1.8" "2.1"  "2.25" "2.4" "3" "3.75" "4.5"
                     "5.25" "6" "7.5" "9" "10.5"  "12"  "13.5" "15" "17.5" "18"   ))
         (setq fhyy3 (atoi (get_tile "list_changd3" )))
         (setq L3  (nth fhyy3 yyg3 ))
)
(defun flist4 ()                                               ;向第四个退刀槽相差列表框中填内容
         (setq yyg4 '("0.8"  "1" "1.1"  "1.2" "1.3" "1.6" "2" "2.3"
                     "2.6" "3" "3.6" "4.4" "5"  "5.7"  "6.4" "7" "7.7" "8.3"       ))
         (start_list "list_zhij3")
         (mapcar 'add_list yyg4)
         (end_list)
)
(defun tqlist4 ()                                             

         (setq yyg4 '("0.8"  "1" "1.1"  "1.2" "1.3" "1.6" "2" "2.3"
                     "2.6" "3" "3.6" "4.4" "5"  "5.7"  "6.4" "7" "7.7" "8.3"       ))
         (setq fhyy4 (atoi (get_tile "list_zhij3" )))
         (setq D3  (nth fhyy4 yyg4 ))
)
(defun flist5 ()                                               ;向第五个键槽宽度列表框中填内容
         (setq yyg5 '("2"  "3" "4"  "5" "6" "8" "10" "12"
                     "14" "16" "18" "20" "22"  "25"  "28"  ))
         (start_list "list_kuand")
         (mapcar 'add_list yyg5)
         (end_list)
)
(defun tqlist5 ()                                             

         (setq yyg5 '("2"  "3" "4"  "5" "6" "8" "10" "12"
                     "14" "16" "18" "20" "22"  "25"  "28"  ))
         (setq fhyy5 (atoi (get_tile "list_kuand" )))
         (setq b  (nth fhyy5 yyg5 ))
)
(defun flist6 ()                                               ;向第六个轴深列表框中填内容
         (setq yyg6 '("1.2"  "1.8" "2.5"  "3.0" "3.5" "4.0" "5.0" "5.5"
                     "6.0" "7.0" "7.5" "9.0" "10.0"  ))
         (start_list "list_zhoush")
         (mapcar 'add_list yyg6)
         (end_list)
)
(defun tqlist6 ()                                             

         (setq yyg6 '("1.2"  "1.8" "2.5"  "3.0" "3.5" "4.0" "5.0" "5.5"
                     "6.0" "7.0" "7.5" "9.0" "10.0"  ))
         (setq fhyy6 (atoi (get_tile "list_zhoush" )))
         (setq h  (nth fhyy6 yyg6 ))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;画图函数
(defun jxone ()   
  ;(setq start (getpoint "确定基点:"))
  ;(setq l1 (getreal "\n输入轴段长度:"))
  ;(setq D1 (getreal "\n输入轴段宽度:"))
  ;(setq l2 (getreal "\n输入倒角长度:"))

  (setq p2 (polar start alph C))
  (setq p3 (polar start alph L1))
  (setq p4 (polar start (+ alph (* 0.5 pi))  (- (* 0.5 D1) C)))
  (setq p5 (polar p2 (+ alph (* 0.5 pi))  (* 0.5 D1)))
  (setq p6 (polar p3 (+ alph (* 0.5 pi))  (* 0.5 D1)))
  (setq p19 (polar start (+ alph pi) (* 0.2 D1)))
  (setq p20 (polar p3 alph (* 0.2 D1)))

  (command "layer" "s" "draw" "")
  (command "pline" start "w" 0.1 "" p4 p6 p5 p3 "")
  (setq ss (ssadd(entlast)))

  (command "line" p2 p5 "")
  (setq ss (ssadd(entlast)ss))
  (command "mirror" ss "" start p3 "")

  (command "layer" "s" "center" "")
  (setq p19 (polar start (+ alph pi) (* 0.2 D1)))
  (setq p20 (polar p2 alph (* 0.2 D1)))  
  (command "line" p19 p20 "")  
  (setq ss1 (ssadd(entlast)))  
)


(defun jxthree()
  ;(setq start (getpoint "确定基点"))
  ;(setq L1 (getreal "\n输入轴段长度"))
  ;(setq D1 (getreal"\n输入轴段宽度"))

  (setq p2 (polar start alph L1))
  (setq p3 (polar start (+ alph (* 0.5 pi)) (* 0.5 D1)))
  (setq p4 (polar p2 (+ alph (* 0.5 pi))  (* 0.5 D1)))
  (command "layer" "s" "draw" "")
  (command "pline" start "w" 0.1 "" p3 p4 p2 "")
  (setq ss (ssadd(entlast)))
  (command "mirror" ss "" start p2 "")
  (command "layer" "s" "center" "")
  (setq p19 (polar start (+ alph pi) (* 0.2 D1)))
  (setq p20 (polar p2 alph (* 0.2 D1)))  
  (command "line" p19 p20 "")  
   (setq ss1 (ssadd(entlast)))
      )






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

本版积分规则

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

GMT+8, 2024-3-28 17:02 , Processed in 0.284004 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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