明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2346|回复: 4

[求助]为什么同一个程序在学校的机器上画出的图和我家的机器上画的图不一样

[复制链接]
发表于 2002-5-15 13:32 | 显示全部楼层 |阅读模式
(都是用的AutoCAD2000环境下)下面是这个绘图程序的源代码(用Autolisp编的),请大家帮帮我,我星期一就要用此程序答辨了!!

(defun c:th ()
(defun cl ()
    (setq dw (atof (get_tile "dw")))    ;/*把"dw"的值付给dw*/
    (setq dd (atof (get_tile "dd")))
    (setq bp (atof (get_tile "bp")))
    (setq ha (atof (get_tile "ha")))
    (setq hf (atof (get_tile "hf")))
    (setq e (atof (get_tile "e")))
    (setq f (atof (get_tile "f")))
    (setq yi (atof (get_tile "yi")))
    (setq db (atof (get_tile "db")))
    (setq fai (atof (get_tile "fai")))
    (setq xd (atof (get_tile "xd")))
    (setq l (atof (get_tile "l")))
    (setq xb (atof (get_tile "xb")))
    (setq n (atof (get_tile "n")))
  )
  (setq dcl_id (load_dialog "dcl.dcl"))    ;/*设置一个对话框,调用dcl.dcl*/
  (if (< dcl_id 0) (exit))    ;/*如果dcl_id<0 退出*/
  (setq dw 95.50)    ;/*付值*/
  (setq dd 90.00)
  (setq bp 11.00)
  (setq ha 2.75)
  (setq hf 8.70)
  (setq e 15.00)
  (setq f 10.00)
  (setq yi 6.00)
  (setq db 65.00)
  (setq fai 34.00)
  (setq xd 36.00)
  (setq l 72.00)
  (setq xb 13.20)
  (setq n 4.00)
  (if (not (new_dialog "ht" dcl_id))    ;/*如果不为"ht"就退出*/
    (exit)
  )
  (set_tile "dw" (rtos dw 2 2))    ;/*设置对话框控键的值为十进制,保留两位小数*/
  (set_tile "dd" (rtos dd 2 2))
  (set_tile "bp" (rtos bp 2 2))
  (set_tile "ha" (rtos ha 2 2))
  (set_tile "hf" (rtos hf 2 2))
  (set_tile "e" (rtos e 2 2))
  (set_tile "f" (rtos f 2 2))
  (set_tile "yi" (rtos yi 2 2))
  (set_tile "db" (rtos db 2 2))
  (set_tile "fai" (rtos fai 2 2))
  (set_tile "xd" (rtos xd 2 2))
  (set_tile "l" (rtos l 2 2))
  (set_tile "xb" (rtos xb 2 2))
  (set_tile "n" (rtos n 2 2))
  (action_tile
    "dw"
    "(set_tile $key (rtos (atof $value) 2 2))"    ;/*把后面的转换成浮点型付给dw*/
  )
  (action_tile
    "bp"
    "(set_tile $key (rtos (atof $value) 2 2))"
  )
  (action_tile
    "ha"
    "(set_tile $key (rtos (atof $value) 2 2))"
  )
  (action_tile
    "hf"
    "(set_tile $key (rtos (atof $value) 2 2))"
  )
  (action_tile "e" "(set_tile $key (rtos (atof $value) 2 2))")
  (action_tile "f" "(set_tile $key (rtos (atof $value) 2 2))")
  (action_tile
    "yi"
    "(set_tile $key (rtos (atof $value) 2 2))"
  )
  (action_tile
    "fai"
    "(set_tile $key (rtos (atof $value) 2 2))"
  )
  (action_tile
    "xd"
    "(set_tile $key (rtos (atof $value) 2 2))"
  )
  (action_tile "l" "(set_tile $key (rtos (atof $value) 2 2))")
  (action_tile
    "xb"
    "(set_tile $key (rtos (atof $value) 2 2))"
  )
  (action_tile "n" "(set_tile $key (rtos (atof $value) 2 2))")
  (action_tile "accept" "(cl)(done_dialog)")
  (action_tile "cancel" "(quit)")
  (start_dialog)
  (setq fi (* (/ PI 180) fai))    ;/*把角度转换成弧度*/
  (setq O '(240.00 145.00))    ;/*原点坐标*/
  (command "layer" "n" 1 "n" 2 "c" 1 1 "c" 255 2 "l" "center" 1        "lw" 0.2  2 "")    ;/*定义图层,颜色,线形*/
  (command "ltscale" 10)     ;/*线的比例因数*/
  (command "setvar" "blipmode" 0 "setvar" "cmdecho" 1)
  (command "layer" "s" 2 "")
  (setq O1 (polar O (/ PI 2.00) (* (/ 11.00 20.00) xd)))    ;/*开始描点*/
  (setq        G1 (polar O1
                  (/ PI 2.00)
                  (- (/ dw 2.00) (* (/ 11.00 20.00) xd))
           )
  )
  (setq q1 (- f (/ bp 2.00)))
  (setq q2 (/ (- dw dd) 2.00))
  (setq        q3 (sin (/ fi 2.00))
        q4 (cos (/ fi 2.00))
        q5 (/ q3 q4)
  )
  (setq G2 (polar G1 0.00 (- q1 (* q2 q5))))
  (setq G3 (polar G2 (- (/ fi 2.00) (/ PI 2.00)) (+ ha hf)))
  (setq q6 (car G3))
  (setq G4 (polar G3 0.00 (* (- (+ f 240) q6) 2)))
  (setq        G5 (polar G4
                  (- (+ (/ fi 2.00) (/ PI 2.00)) fi)
                  (+ ha hf)
           )
  )
  (setq G6 (polar G5 0.00 (- e xb)))
  (setq k 0)
  (while (<= k (- n 2))
    (setq q7 (distance G2 G6))
    (setq g (polar G2 0.00 (* (+ k 1) q7)))
    (setq G7 (polar g (- (/ fi 2.00) (/ PI 2.00)) (+ ha hf)))
    (setq G8 (polar G7 0.00 (* (- (+ f 240) q6) 2)))
    (setq G9 (polar G8
                    (- (+ (/ fi 2.00) (/ PI 2.00)) fi)
                    (+ ha hf)
             )
    )
    (setq G10 (polar G9 0.00 (- e xb)))
    (command "pline" g G7 G8 G9 G10 "")    ;/*用多艺线连接各点*/
    (setq k (+ 1 k))
  )
  (command "pline" O1 G1 G2 G3 G4 G5 G6 "")
  (setq q8 (polar G2 0.00 (- (* n q7) (- e xb))))
  (setq q9 (distance G1 q8))
  (setq G11 (polar q8 0.00 (- db q9)))
  (setq G12 (polar G11 (- (/ PI 2.00)) (- (/ dw 2.00) (* xd 0.90))))
  (if (>= l db)    ;/*如果执行11>=db否则执行2*/
    (subr1)
    (subr2)
  )

  (setq q10 (car G16))
  (if (<= db l)
    (setq q11 l)
    (setq q11 db)
  )
  (setq G21 (polar G11 0.00 (+ (- (+ q11 240.00) q10) 50.00)))
  (setq G22 (polar G21 (- (/ PI 2)) (/ dw 2)))
  (setq G23 (polar G22 (- (/ PI 2)) (/ dw 2)))
  (command "arc" "CE" G22 G23 "a" "180")
  (setq G24 (polar G22 (- (/ PI 2)) (+ (/ xd 2.00) (/ xd 20.00))))
  (command "arc" "CE" G22 G24 "a" "180")
  (setq G25 (polar G22 (- (/ PI 2)) (/ xd 2.00)))
  (command "arc" "CE" G22 G25 "a" "180")
  (setq G26 (polar O PI 20.00))
  (setq G27 (polar G22 0.00 (+ (/ dw 2) 20.00)))
  (setq G28 (polar G21 (/ PI 2.00) 20.00))
  (setq G29 (polar G23 (- (/ PI 2.00)) 20.00))
  (setq G30 (polar O (/ PI 2) (/ dd 2)))
  (setq G31 (polar O (- (/ pi 2)) (/ dd 2)))
  (setq G32 (polar G30 PI 10.00))
  (setq G33 (polar G32 0.00 (+ db 20.00)))
  (setq G34 (polar G31 PI 10.00))
  (setq G35 (polar G34 0.00 (+ db 20.00)))
  (setq G36 (polar G22 (- (/ Pi 2)) (/ dd 2)))
  (command "layer" "s" 1 "")
  (command "line" G26         G27        ""     "line" G28    G29    ""
           "line" G32         G33        ""     "line" G34    G35    ""
          )
  (command "arc" "CE" G22 G36 "a" "180")
  (command "layer" "s" 2 "")
  (setq G37 (polar O PI 40))
  (setq G38 (polar G37 (/ PI 2) (+ (/ dw 2) 40)))
  (setq G39 (polar G38 0.00 (+ (* q11 2) 100)))
  (setq G40 (polar G39 (- (/ PI 2)) (+ dw 80)))
  (setq G41 (polar G40 PI (distance G38 G39)))
  (command "pline" G38 G39 G40 G41 G38 "")
  (unload_dialog dcl_id)
)

(defun subr1 ()
  (setq        G13 (polar G12 0.00 (- l db (/ xd 20.00)))
        G14 (polar G13 (- (/ PI 4.00)) (* (/ xd 20.00) (sqrt 2.00)))
  )
  (setq        G15 (polar G14
                   (- (/ PI 2.00))
                   (- (last G13) 145.00 (/ xd 20.00))
            )
  )
  (setq G16 (polar G14 (- (/ PI 2.00)) (- (* xd 0.4) (/ xd 10.00))))
  (setq        G17 (polar G16
                   (- (/ (* 3.00 PI) 4.00))
                   (* (/ xd 20.00) (sqrt 2.00))
            )
  )
  (setq G18 (polar G17 PI (- l (/ xd 10.00))))
  (setq        G19 (polar G17
                   (- (/ PI 2.00))
                   (- (distance G15 G16) (/ xd 20.00))
            )
  )
  (setq        G20 (polar G18
                   (- (/ PI 2.00))
                   (- (distance G15 G16) (/ xd 20.00))
            )
  )
  (setq q12 (last G12))
  (setq G42 (polar G12 (- (/ PI 2)) (- q12 140)))
  (command "pline" q8 G11 G12 G13 G14 G16 G17 G18 O1 "")
  (setq s1 (ssget "X"))    ;/*把已经画好的图形全部付给实体集s1*/
  (command "mirror" s1 "" O G15 "")    ;/*以0,G15线做镜象*/
  (setq s2 (ssget "x"))
  (command "layer" "s" 0 "")
  (command "hatch" "u" 45.00 2.00 "" s2 "")
  (command "layer" "s" 2 "")
  (command "pline" G17 G19 "")
  (setq s3 (entlast))
  (command "mirror" s3 "" O G15 "")
  (command "pline" G18 G20 "")
  (setq s4 (entlast))
  (command "mirror" s4 "" O G15 "")
  (command "pline" O1 O "")
  (setq s5 (entlast))
  (command "mirror" s5 "" O G15 "")
  (command "pline" G15 G16 "")
  (setq s6 (entlast))
  (command "mirror" s6 "" O G15 "")

)


(defun subr2 ()
  (setq        G13 (polar G12 PI (- db l (/ xd 20.00)))
        G14 (polar G13
                   (- (/ (* PI 3) 4.00))
                   (* (/ xd 20.00) (sqrt 2.00))
            )
  )
  (setq        G15 (polar G14
                   (- (/ PI 2.00))
                   (- (last G13) 145.00 (/ xd 20.00))
            )
  )
  (setq G16 (polar G14 (- (/ PI 2.00)) (- (* xd 0.4) (/ xd 10.00))))
  (setq        G17 (polar G16
                   (- (/ (* 3.00 PI) 4.00))
                   (* (/ xd 20.00) (sqrt 2.00))
            )
  )
  (setq G18 (polar G17 PI (- l (/ xd 10.00))))
  (setq        G19 (polar G17
                   (- (/ PI 2.00))
                   (- (distance G15 G16) (/ xd 20.00))
            )
  )
  (setq        G20 (polar G18
                   (- (/ PI 2.00))
                   (- (distance G15 G16) (/ xd 20.00))
            )
  )
  (setq q12 (last G12))
  (setq G42 (polar G12 (- (/ PI 2)) (- q12 140)))
  (command "pline" q8 G11 G12 G13 G14 G16 G17 G18 O1 "")
  (setq s1 (ssget "X"))
  (command "mirror" s1 "" O G15 "")
  (setq s2 (ssget "x"))
  (command "layer" "s" 0 "")
  (command "hatch" "u" 45.00 2.00 "" s2 "")
  (command "layer" "s" 2 "")
  (command "pline" G17 G19 "")
  (setq s3 (entlast))
  (command "mirror" s3 "" O G15 "")
  (command "pline" G18 G20 "")
  (setq s4 (entlast))
  (command "mirror" s4 "" O G15 "")
  (command "pline" O1 O "")
  (setq s5 (entlast))
  (command "mirror" s5 "" O G15 "")
  (command "pline" G15 G16 "")
  (setq s6 (entlast))
  (command "mirror" s6 "" O G15 "")
  (command "pline" G12 G42 "")
  (setq s7 (entlast))
  (command "mirror" s7 "" O G15 "")

)
发表于 2002-5-15 13:54 | 显示全部楼层

请问不一样在什么地方?

 楼主| 发表于 2002-5-15 13:54 | 显示全部楼层

忘了帖dcl文件,现加上!

此为dcl.dcl文件源代码


ht:dialog{
    label="v带轮传动参数";
    :text{
     label="长度单位(毫米)       角度单位(度)";
          }
    :row{
    :boxed_column{
    :edit_box{
     key="dw";
     label="外径(dw)";
     mnemonic="dw";
     edit_width=8;
              }
    :edit_box{
     key="dd";
     label="基准直径(dd)";
     mnemonic="dd";
     edit_width=8;
              }
    :edit_box{
     key="bp";
     label="基准宽度(bp)";
     mnemonic="bp";
     edit_width=8;
              }
    :edit_box{
     key="ha";
     label="基准线上槽深(hamin)";
     mnemonic="ha";
     edit_width=8;
              }
    :edit_box{
     key="hf";
     label="基准线下槽深(hfmin)";
     mnemonic="hf";
     edit_width=8;
              }
    :edit_box{
     key="e";
     label="槽间距(e)";
     mnemonic="e";
     edit_width=8;
               }
    :edit_box{
     key="f";
     label="第一槽对称面至端面距离(f)";
     mnemonic="f";
     edit_width=8;
               }
            }
    :boxed_column{
    :edit_box{
     key="yi";
     label="最小轮缘厚(yimin)";
     mnemonic="yi";
     edit_width=8;
               }
    :edit_box{
     key="db";
     label="带轮宽(db)";
     mnemonic="db";
     edit_width=8;
               }
    :edit_box{
     key="fai";
     label="轮槽角(fai)";
     mnemonic="fai";
     edit_width=8;
               }
    :edit_box{
     key="xd";
     label="动力输入轴直径(xd)";
     mnemonic="xd";
     edit_width=8;
               }
    :edit_box{
     key="l";
     label="带轮轮毂部分厚度(l)";
     mnemonic="l";
     edit_width=8;}
    :edit_box{
     key="xb";
     label="齿槽宽(xb)";
     mnemonic="xb";
     edit_width=8;}
    :edit_box{
     key="n";
     label="轮齿数(n)";
     mnemonic="n";
     edit_width=8;}}}
     spacer_1;
     ok_cancel;
     errtile;}
发表于 2002-5-15 14:57 | 显示全部楼层

捕捉问题,见内

前一句改为:
(defun c:th ()
  (setq oldecho(getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq oldsnap(getvar "osmode"))
  (setvar "osmode" 0)

中间的:  (command "setvar" "blipmode" 0 "setvar" "cmdecho" 1)
改为:  (command "setvar" "blipmode" 0 )

结束的:改为
  (setvar "cmdecho" oldecho)
  (setvar "osmode" oldsnap)

)

这样就可以画出正确的图形了。但程序还需要一些优化,大家说说吧
发表于 2002-5-15 20:26 | 显示全部楼层

约束的东西太多,不改参数值则正常,改了某些值后就不正常了

以下是改了默认的参数值就变成这样了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

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

GMT+8, 2024-6-17 03:22 , Processed in 0.157351 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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