AutoLISP绘制玻璃门
2011-04-05 16:38 精诚所至 金石为开 阅读(686) 评论(0) 编辑 收藏 举报AutoLISP绘制玻璃门,代码如下。
(defun c:test ()
(setvar "cmdecho" 0)
(setq os (getvar "osmode"))
(setq oldlayer (getvar "clayer"))
(setvar "osmode" 0)
(get_door_bas_pp)
(sub_demodoor1)
(initget "Yes No")
(setq mirr (getkword "\n镜射另一片门吗?[是\(Y\)/(否\(N\),<N>:"))
(if (= mirr "Yes")
(command "mirror"
(ssget "c" bas_p1 bas_p3)
""
bas_p2
bas_p3
""
)
)
(setvar "osmode" os)
(setvar "clayer" oldclayer)
(prin1)
)
(defun get_door_bas_pp ()
(setq bas_ip_list '())
(setq bas_p1 (getpoint "门得左下角点:"))
(setq dr_w (getreal "\n门宽<90>:"))
(if (null dr_w)
(setq dr_w 90)
)
(setq dr_n1 (getreal "\n门左边高度<100>:"))
(if (null dr_h1)
(setq dr_n1 100)
)
(setq dr_h2 (getreal "\n门突出高度<30>:"))
(if (null dr_h2)
(setq dr_h2 30)
)
(setq dr_c (getreal "\n门左边平台宽度<15>:"))
(if (null dr_c)
(setq dr_c 15)
)
(setq
sca (getstring
"\n门的上方弧度 1/1,2/1,3/1,4/1,5/1,1/2,1/3,1/4,1/5<1/1>:"
)
)
(if (= sca "")
(setq sca "1/1")
)
(setq gap (getreal "\n门内框偏移量<5>:"))
(if (null gap)
(setq gap 5)
)
(setq bas_p2 (polar bas_p1 0 dr_w))
(setq bas_p3 (polar bas_p2 (* pi 0.5) dr_h1))
(setq bas_p4 (polar bas_p1 (* pi 0.5) dr_h1))
(setq mid_pp (inters bas_p1 bas_p3 bas_p2 bas_p4))
(setq bas_p3t (polar bas_p3 (* pi 0.5) dr_h2))
(if (and dr_c (> dr_c 0))
(setq pt4 (polar bas_p4 0 dr_c))
(setq pt4 bas_p4
dr_c 0
)
)
)
(defun sub_demodoor1 ()
(setq len_34 (distance pt4 bas_p3t))
(setq ang_34 (angle pt4 bas_p3t))
(cond
((member sca '("1/1" "2/1" "3/1" "4/1" "5/1"))
(setq pt5 (polar pt4 ang_34 (/ len_34 (1+ (cal sca)))))
)
((member sca '("1/2" "1/3" "1/4"))
(setq pt5 (polar pt4 ang_34 (* (/ len_34 3) (/ 1 (cal sca)))))
)
)
(command "-layer" "m" "str" "c" 4 "" "")
(if (> dr_c 0)
(command "pline" bas_p1 bas_p2 bas_p3t "a" "d" "180" pt5 pt4 "1"
bas_p4 "c")
(command "pline" bas_p1 bas_p2 bas_p3t "a" "d" "180" pt5 pt4 "1" "c")
)
(setq offset_pt (polar bas_p1 (/ pi 4) (* gap 2)))
(command "offset" gap (entlast) offset_pt "")
(command "-layer" "m" "hat" "c" 6 "" "")
(setvar "hpname" "SACNCR")
(setvar "hpscale" 4)
(bhatch offset_pt)
(command "-layer" "m" "dim" "c" 1 "" "")
(command "dim1"
"hor"
bas_p1
bas_p2
(polar bas_p1 (* pi 1.5) 10)
""
)
(command "dim1" "ver" bas_p1 bas_p4 (polar bas_p1 pi 10) "")
)
(defun c:test1 ()
(setvar "cmdecho" 0)
(setq os (getvar "osmode"))
(setq oldlayer (getvar "clayer"))
(setvar "osmode" 0)
(setq bas_p1 (getpoint "门的左下角:"))
(setq dr_w (getreal "\n门总宽<90>:"))
(if (null dr_w)
(setq dr_w 90)
)
(setq dr_h (getreal "\n门总高<200>:"))
(if (null dr_h)
(setq dr_h 200)
)
(setq n (getint "\n内部玻璃数量<5>:"))
(if (null n)
(setq n 5)
)
(setq gap1 (getreal "\n门框宽度<12>:"))
(if (null gap1)
(setq gap1 12)
)
(setq gap2 (getreal "\n玻璃间距<5>:"))
(if (null gap2)
(setq gap2 5)
)
(command "-layer" "m" "str" "c" 4 "" "")
(command "rectang" bas_p1 (polarxy bas_p1 dr_w dr_h))
(setq ins_pt (polarxy bas_p1 gap1 gap1))
(setq gw (- dr_w gap1 gap1))
(setq gh (/ (- dr_h (* gap1 2) (* gap2 (1- n))) n))
(command "rectang" ins_pt (polarxy ins pt gw gh))
(command "array" (entlast) "" "r" n 1 (- gn gap2))
(command "-layer" "m" "dim" "c" 1 "" "")
(command "dim1"
"hor"
bas_p1
(polar bas_p1 0 dr_w)
(polar bas_p1 (* pi 1.5) 10)
""
)
(command "dim1"
"ver"
bas_p1
(polar bas_p1 (/ pi 2) dr_h)
(polar bas_p1 pi 10)
""
)
(setvar "osmode" os)
(setvar "clayer" oldclayer)
(prin1)
)
(defun polarxy (#pp #x #y)
(setq px (car #pp)
py (cadr #pp)
)
(list (+ px #x) (+ py #y))
)
(princ "\n------<C:TEST>------")
(prin1)
代码完。