; Draws continuous pipe (or duct) of any size with user defined inner bend radius (default = 0.0)

(defun c:dcd (/ d1 d p1 p2 p3 rd1 rd2 lu1 lu2 u1 u2 u3 u5 erd elu erd2
elu2 ofr)
(setq oerr *error*)
(defun *error* (msg)
(setvar "filletrad" ofr)
(setvar "osmode" osn)
(princ
"Function cancelled by user, or radius is too large "
)
(setq *error* oerr)
(command)
(princ)
)
(setq osn (getvar "osmode"))
(setq ofr (getvar "filletrad"))
(setvar "cmdecho" 0)
(if (= d2 nil)
(setq d2 1.0)
)
(princ "\n Pipe diameter / duct width ?:")
(setq d1 (getdist))
(if (= d1 nil)
(setq d1 d2)
)
(setq d2 d1)
(if (= r1 nil)
(setq r1 0.0)
)
(princ "\n Inner bend radius ?:")
(setq r (getdist))
(if (= r nil)
(setq r r1)
)
(setq r1 r)
(setq d (/ d1 2))
(setq p1 (getpoint "\n Start point: "))
(setq p2 (getpoint p1 "\n Next point: "))
(setq u1 (angle p1 p2))

(setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; rd = right
(setq rd2 (polar rd1 u1 (distance p1 p2)))
(setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; lu = left
(setq lu2 (polar lu1 u1 (distance p1 p2)))
(setvar "osmode" 0)
(command "line" rd1 lu1 "")
(command "line" rd1 rd2 "")
(setq erd (entlast))
(command "line" lu1 lu2 "")
(setq elu (entlast))
(setvar "osmode" osn)
(setq p3 (getpoint p2 "\n Next"))
(setvar "osmode" 0)
(setq u2 (angle p2 p3))

(setq u5 (+ (- pi u1) u2))
(if (> u5 (* pi 2))
(setq u5 (- u5 (* pi 2)))
)
(if (< u5 0)
(setq u5 (+ (* pi 2) u5))
)

(while p3
(setq p1 p2)
(setq p2 p3)
(setq u1 (angle p1 p2))

(setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; rd = right/down
(setq rd2 (polar rd1 u1 (distance p1 p2)))
(setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; lu = left/up
(setq lu2 (polar lu1 u1 (distance p1 p2)))
(command "line" rd1 rd2 "")
(setq erd2 (entlast))
(command "line" lu1 lu2 "")
(setq elu2 (entlast))

(if ( u5 pi)
(progn
(setvar "filletrad" (+ d1 r))
(command "fillet" erd erd2)
(setvar "filletrad" r)
(command "fillet" elu elu2)
)
)

(setq erd erd2)
(setq elu elu2)
(setvar "osmode" osn)
(setq p3 (getpoint p2 "\n Next:"))
(setvar "osmode" 0)
(if (= p3 nil)
()
(setq u2 (angle p2 p3))
)

(setq u5 (+ (- pi u1) u2))
(if (> u5 (* pi 2))
(setq u5 (- u5 (* pi 2)))
)
(if (< u5 0)
(setq u5 (+ (* pi 2) u5))
)

)

(command "line" rd2 lu2 "")
(setvar "osmode" osn)
(setvar "filletrad" ofr)
(princ)
)
(c:dcd)

Advertisements