000000 发表于 2011-6-21 16:19:42

编制一个端板开孔程序,关键坐标控制不住不让它变

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;端板
(defun c:db()
(hhh)
(draw_pbox)
(draw_blot)
(draw_blot_add)
(prin1)
)
(defun hhh ();绘制H钢
    (setq bas0 (getpoint "\nPick the center-point of the H-type : " ))
(setq    bf (getdist "\nInput the flange-width of the H-typebf= <200>"))
(setq    tw (getdist "\nInput the web-thick of the H-typetw=<6> "))
(setqtf (getdist "\nInput the flange-thick of the H-typetf= <8>"))
(setqx0 (car   bas0)
      y0 (cadrbas0)
      bf2 (/ bf 2.)
      h2(/ h 2.)
      h02 (- h2 tf)
)
(setq old_cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "line" "non" (list (+ x0 bf2) (+ y0 h2))
                  "non" (list (+ x0 bf2) (+ y0 h02))
                  "non" (list (- x0 bf2) (+ y0 h02))
                  "non" (list (- x0 bf2) (+ y0 h2 ))
                  "non" (list (+ x0 bf2) (+ y0 h2))""
         "line" "non" (list (+ x0 bf2) (- y0 h2))
                  "non" (list (+ x0 bf2) (- y0 h02))
                  "non" (list (- x0 bf2) (- y0 h02))
                  "non" (list (- x0 bf2) (- y0 h2 ))
                  "non" (list (+ x0 bf2) (- y0 h2))""
         "line" "non" (list (+ x0 (/ tw 2)) (+ y0 h02))
                  "non" (list (+ x0 (/ tw 2)) (- y0 h02))""
         "line" "non" (list (- x0 (/ tw 2)) (+ y0 h02))
                  "non" (list (- x0 (/ tw 2)) (- y0 h02))""
    )                                                                     
   (setvar "cmdecho" old_cmd)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;绘制端板 之前没问题,到这后面,bas0的坐标就乱了,不知道什么原因,不再继承前面的
(defun draw_pbox(/ pa pb pc pd )
(setq bw (+ bf 20.))
(setq bh (+ h 180.))
(setq bw1 (/ bw 2)
bh1 (/ bh 2)
)
(setq pa (list (- x0 bw1) (- y0 bh1)))
(setq pb (polar pa 0 bw))
(setq pc (polar pb (/ pi 2) bh))
(setq pd (polar pc pi bw))
(command"pline" pa pb pc pd "c")
(command"rectang" (mapcar '- bas0(list 4 0 0)) (mapcar '+ bas0(list 4 0 0)))
(command "mirror" (entlast) "" bas0 (mapcar '- bas0(list 1 0 0)) "n" )
)
;;;;;;;;;;;;绘制锚栓 这个编制的很乱,不怎么会用选择
(defun draw_blot ()
(setq pta (list (- x0 45.) (- y0 h2 45.)))
(setq      pta1 (list (- x0 45.) (+(- y0 h2 )60.)))
(setq ptb (list (+ x0 45.) (- y0 h2 45.)))
(setq   ptb1 (list (+ x0 45.) (+(- y0 h2 )60.)))
(setq ptc (list (+ x0 45.) (+ y0 h2 45.)))
(setq      ptc1 (list (+ x0 45.) (-(+ y0 h2 )60.)))
(setq ptd (list (- x0 45.) (+ y0 h2 45.)))
(setq      ptd1 (list (- x0 45.) (-(+ y0 h2 )60.)))
(command "circle" pta 11) (setq en1 (entlast))
(command "copy" en1 "" "m" pta ptb ptc ptd pta1 ptb1 ptc1 ptd1 "")
)
(defun draw_blot_add ()
(setq nb (getdist "\n内侧附加螺栓排数:<1>"))
(cond ((= nb nil)
(command "copy" en1"" "m"pta (list (car pta) y0 ) (list (car ptb) y0) ""))
((= nb 2)
(command "copy" en1"" "m"pta (list (car pta) (- (+ y0 h2 ) 160.)) (list (car ptb) (-(+ y0 h2 ) 160.))
                            (list (car pta) (+(- y0 h2 ) 160.)) (list (car ptb) (+(- y0 h2 ) 160.))""))
((= nb 3)
(command "copy" en1"" "m"pta(list (car pta) y0 ) (list (car ptb) y0)
                            (list (car pta) (-(+ y0 h2 ) 160.)) (list (car ptb) (-(+ y0 h2 ) 160.))
                            (list (car pta) (+(- y0 h2 ) 160.)) (list (car ptb) (+(- y0 h2 ) 160.))""))
         (t (print "\n 内侧不加螺栓"))
)
)
   ;我刚学lisp ,做了几个,经常出现第二次,使用,某些值就乱了,难道是要设局部变量,可是我不太会设置后或者没用,或者不让执行, 希望哪位朋友能指点迷津!先谢谢了。
我qq1457061501(请注明lisp), 如果不好说清,能否加我qq帮助,多谢了

ZZXXQQ 发表于 2011-6-21 20:34:35

问题:
1、变量h在什么地方赋的值?
2、不出错的程序用了"non" 。在出错的程序中所有坐标点前加上"non" 。

000000 发表于 2011-6-27 09:44:46

谢谢ZZXXQQ
漏了点,我重新发下 :
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;端板
(defun c:db()
(hhh)
(draw_pbox)
(prin1)
)
(defun hhh ();(/ bas0 h bf tw tf x0 y0 bf2 h2 h02 ts old_cmd)
(princ "\nThis command is used to draw a H-type steel")
(setq bas0 (getpoint "\nPick the center-point of the H-type : " ))
(setq h(getdist "\nInput the height of the H-typeH= <500>"))
       (if (= h nil) (setq h 500))
(setq    bf (getdist "\nInput the flange-width of the H-typebf= <200>"))
       (if (= bf nil) (setq bf 200))
(setq    tw (getdist "\nInput the web-thick of the H-typetw=<6> "))
       (if (= tw nil) (setq tw 6))
(setqtf (getdist "\nInput the flange-thick of the H-typetf= <8>"))
       (if (= tf nil) (setq tf 8))
(setqx0 (car   bas0)
      y0 (cadrbas0)
      bf2 (/ bf 2.)
      h2(/ h 2.)
      h02 (- h2 tf)
)
(setq old_cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "line" "non" (list (+ x0 bf2) (+ y0 h2))
                  "non" (list (+ x0 bf2) (+ y0 h02))
                  "non" (list (- x0 bf2) (+ y0 h02))
                  "non" (list (- x0 bf2) (+ y0 h2 ))
                  "non" (list (+ x0 bf2) (+ y0 h2))""
         "line" "non" (list (+ x0 bf2) (- y0 h2))
                  "non" (list (+ x0 bf2) (- y0 h02))
                  "non" (list (- x0 bf2) (- y0 h02))
                  "non" (list (- x0 bf2) (- y0 h2 ))
                  "non" (list (+ x0 bf2) (- y0 h2))""
         "line" "non" (list (+ x0 (/ tw 2)) (+ y0 h02))
                  "non" (list (+ x0 (/ tw 2)) (- y0 h02))""
         "line" "non" (list (- x0 (/ tw 2)) (+ y0 h02))
                  "non" (list (- x0 (/ tw 2)) (- y0 h02))""
)
(setq ts (tblsearch "layer" "axis"))                     
(if (null ts)                                          
    (progn                                                
      (prompt "\nCreating new layer ---AXIS")            
      (command "layer" "new" "axis" "C" "4" "axis" "")   
    )                                                      
)                                                      
(command "line" "non" (list (- x0 (* 1.2 bf2)) y0)
                  "non" (list (+ x0 (* 1.2 bf2)) y0) ""       
         "change" "l" "" "p" "la" "axis" ""
         "line" "non" (list x0 (- y0 (* 1.5 h2)))
                  "non" (list x0 (+ y0 (* 1.5 h2)))""       
         "change" "l" "" "p" "la" "axis" ""
)
(setvar "cmdecho" old_cmd)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun draw_pbox()
(setq bw (+ bf 20))
(setq bh (+ h 180))
(setq        bw1 (/ bw 2.)
        bh1 (/ bh 2.)
)
(setq pa (list (- x0 bw1) (- y0 bh1)))
(setq pb (polar pa 0 bw))
(setq pc (polar pb (/ pi 2) bh))
(setq pd (polar pc pi bw))
(command"pline" pa pb pc pd "c")

(setq tt(getdist "\n加劲板厚度:<10>"))
(if (= tt nil)
    (setq tt 10)
)
(setqt2 (/ tt 2))
(command"rectang" (list(- x0 t2) (+ y0 h2)) (list(+ x0 t2)(+ y0 h2 85.)) )
(command "mirror" (entlast) "" bas0 (list (+ x0 1.)y00) "n" )
)
加载后绘制一个后,画第二个第三个就错了。
下面这个也是同样问题:
(defun c:gj ()
                                        ;以下 H1、L1、L2 、k值须由用户输入
(setq chklay (tblsearch "layer" "gj"))
(if (= chklay nil)
    (command "layer" "n" "gj" "c" "3" "gj" "s" "gj" "")
)
(setq p1 (getpoint "\n输入左下角点:"))
(setq h1 (getdist p1 "\n柱高H1:"))
(setq ch1 (getdist"\n柱小头截面高度ch1:"))
(setq ch2 (getdist"\n柱大头截面高度ch2:"))
(setq i (getreal "\n斜率k:"))
(setq l1 (getdist "\n第一段梁长L1:"))
(setq l2 (getdist "\n第二段梁长L2:"))
(setq bh1 (getdist"\n第一段梁左端截面高度Bh1:"))
(PRINT 111)
        ;以下p2、p3、p4值须由程序依据H1、L1、L2 、K求出
(setq p2 (mapcar '+ p1 (list 0 h1 0)))
(setq p3 (mapcar '+ p2 (list l1 (* l1 i) 0)))
(setq p4 (mapcar '+ p3 (list l2 (* l2 i) 0)))

(setq bh2 (getdist "\n梁右截面高度Bh2:"))
(setq p33 (mapcar '+ p3 (list 0 (- bH2) 0)))

(setq bh3 (getdist "\n第二段梁右端截面高度Bh3:"))
(setq p44 (mapcar '+ p4 (list 0 (- bh3) 0)))

                                        ;以下p11、p22值须由程序求出
(setq p11 (mapcar '+ p1 (list ch1 0 0)))
(setq p22 (mapcar '+ p2 (list ch2 (* ch2 i) 0)))
(setq p20 (mapcar '+ p22 (list 0 (- bh1) 0)))
(command "pline" p20p11 p1 p2 p22 "")
(command "mirror"
           (entlast) ""
           p4p44
           "n"
)


(command "pline" p22 p3 p4 "")
(command "mirror"
           (entlast)
           ""
                p4p44
          "n"
)


(command "pline" p44 p33 p20 "")
(command "mirror"
           (entlast) ""
           p4p44
          "n"
)
(command "zoom" "e")
(PRINT 444)
)
页: [1]
查看完整版本: 编制一个端板开孔程序,关键坐标控制不住不让它变