代码改变世界

AutoLISP板圆三视图

2011-03-28 19:39  精诚所至 金石为开  阅读(394)  评论(0编辑  收藏  举报

AutoLISP板圆三视图,代码如下。

(defun c:test()
  (setvar "cmdecho" 0)
  (setq baspt '(148 105))
  (setq os (getvar "osmode"))
  (setvar "osmode" 0)
  (command "vslide" "LSP_30")
  (setq dd1 (/ (getpoint "\nDD1:") 2))
  (setq dd2 (/ (getpoint "\nDD2:") 2))
  (setq dd3 (/ (getpoint "\nDD3:") 2))
  (setq hh (getdist "\nHH1:"))
  (setq h2 (- hh (getdist "\nHH2:")))
  (redraw)
  (layset)
  (setq cen (polar baspt p1 (* dd1 1.4)))
  (setvar "clayer" "str")
  (command "circle" cen dd1)
  (command "circle" cen dd2)
  (command "circel" cen dd3)
  (command "circle" cen (- dd1 1))
  (setq pp1 (polar cen pi (+ dd1 3)))
  (setq pp2 (polar cen 0 (+ dd1 3)))
  (setq pp3 (polar cen (/ pi 2) (+ dd1 3)))
  (setq pp4 (polar cen (* pi 1.5) (* dd1 3)))
  (setvar "clayer" "cen")
  (command "line" pp1 pp2 "")
  (command "line" pp3 pp4 "")
  (setq pt (polar baspt 0 h2))
  (setq pt1 (polar pt (* pi 1.5) dd2))
  (setq pt2 (polar pt1 0 h2))
  (setq pt3 (polar pt2 (* pi 1.5) (- dd1 dd2 1)))
  (setq pt4 (polar (polar pt3 (* pi 1.5) 1) 0 1))
  (setq pt5 (polar pt4 0 (- hh h2 1)))
  (setq pt6 (polar pt5 (/ pi 2) (* dd1 2)))
  (setq pt7 (polar pt4 (/ pi 2) (* dd1 2)))
  (setq pt8 (polar pt3 (/ pi 2) (- (* dd1 2) 2)))
  (setq pt9 (polar pt2 (/ pi 2) (* dd2 2)))
  (setq pt10 (polar pt2 (/ pi 2) (* dd2 2)))
  (setvar "clayer" "str")
  (command "pline" pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 pt9 pt10 "c")
  (setq pa1 (polar pt pi 3))
  (setq pa2 (polar pt 0 (+ hh 2)))
  (setvar "clayer" "cen")
  (command "line" pa1 pa2 "")
  (setq b1 (polar pt (/ pi 2) dd3))
  (setq b2 (polar b1 0 hh))
  (setq b3 (polar pt (* pi 1.5) dd3))
  (setq b4 (polar b3 0 hh))
  (setvar "clayer" "str")
  (command "line" b1 b2 "")
  (command "line" b3 b4 "")
  (draw_hat)
  (draw_dim)
  (setvar "cmdecho" so)
  (princ "\n------>>LSP_30<<------")
  (prin1)
  )
(defun draw_hat()
  (setq mid1 (polar pt2 (angle pt2 pt5) (/ (distance pt2 pt5) 2)))
  (setq mid2 (polar pt9 (angle pt9 pt6) (/ (distance pt9 pt6) 2)))
  (setvar "hpname" "u")
  (setvar "hpang" (/ pi 4))
  (setvar "hpspace" 3)
  (setvar "clayer" "hat")
  (command "bhatch" mid1 mid2 "")
  )
(defun draw_dim()
  (setvar "clayer" "dim")
  (command "dimlinear" pt8 pt6 (polar pt6 (/ pi 2) 8))
  (command "dimlinear" pt10 pt6 (polar pt6 (/ pi 2) 16))
  (command "dimlinear" b1 b3 "t" "%%c<>" (polar b1 pi 8))
  (command "dimlinear" pt1 pt10 "t" "%%c<>" (polar b1 pi 16))
  (command "dinlinear" pt5 pt6 "t" "%%c<>" (polar pt5 0 8))
  )
(defun layset()
  (command "layer" "n" "str,cen,hid,hat,txt,dim" "c" 1 "str" "c" 2 "cen" "c" 4 "hid" "c" 5 "hat" "c" 6 "txt" "c" 3 "dim" "")
  (setq key (tblsearch "ltype" "center"))
  (if (= key nil) (command "linetype" "1" "center" "acadiso" ""))
  (setq key (tblsearch "ltype" "hidden"))
  (if (= key nil) (command "linetype" "1" "hidden" "adadiso" ""))
  (command "layer" "it" "center" "cen" "it" "hidden" "hid" "")
  )

代码完。

这个有点多,错误不好找。