< >; 绘制椭圆封头的小程序;
; 初学lisp编程的人可以参考;
; Data of the ellipse
(defun data-el ()
(setq ip (getpoint "\nInsert point: "))
(setq dn (getreal "\nDN: "))
(setq t (getreal "\nThickness: "))
(command "osnap" "")
)</P>
<P>; Draw ellipse
(defun draw-el ()
(command "layer" "m" "inte_thick" "color" "white" "" "")
(command "layer" "m" "inte_dashed" "color" "blue" "" "lt" "dashed" "" "")
(command "layer" "m" "inte_center" "color" "red" "" "lt" "center" "" "")
(if (and (>= t 10) (<= t 18)) (setq hi 40))
(if (< t 10) (setq hi 25))
(if (> t 18) (setq hi 50))
(setq sp (mapcar '+ ip (list (- (/ dn 2)) hi 0)))
(setq
ep (mapcar '+ ip (list (/ dn 2) hi 0)))
(setq ep1 (mapcar '+ ep (list 0 (- hi) 0)))
(setq ep2 (mapcar '+ ep (list t (- hi) 0)))
(setq ep3 (mapcar '+ ep (list t 0 0)))
(setq sp1 (mapcar '+ sp (list 0 (- hi) 0)))
(setq sp2 (mapcar '+ sp (list (- t) (- hi) 0)))
(setq sp3 (mapcar '+ sp (list (- t) 0 0)))
(setq ip1 (mapcar '+ ip (list 0 (+ (/ dn 4) (* t 2) hi) 0)))
(command "layer" "s" "inte_thick" "")
(command "ellipse" "a" sp ep (/ dn 4) 180 360)
(command "offset" t (entlast) ip1 "")
(command "layer" "m" "inte_divide" "color" "cyan" "" "lt" "divide" "" "")
(command "layer" "s" "inte_thick" "")
(command "line" sp sp1 sp2
sp3 "")
(command "line" ep ep1 ep2 ep3 "")
(command "line" sp1 ep1 "")
(command "layer" "s" "inte_divide" "")
(command "line" ep3 sp3 "")
(command "change" sset "" "p" "la" "inte_center" "color" "bylayer" "lt" "bylayer" "")
(command "layer" "s" "inte_center" "")
(command "line" ip ip1 "")
(command "osnap" "int,end,mid,cen,tan,per,nea")
)</P>
<P>; Execute command
(defun C:elh ()
(data-el)
(draw-el)
(princ)</P>
<P>) </P>
[此贴子已经被作者于2004-10-11 15:11:03编辑过]
|