;;; Draw user defined diameter duct with radius elbow with center lines (axes)

(defun c:dc (/ d1 d p1 p2 p3 rd1 rd2 lu1 lu2 u1 u2 u3 u5 erd elu erd2
elu2 ofr cl cl1 rc cr u10 u11 pc1 pc2 pc3 pc4 fa)
(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)
)
(command "_.undo" "begin")

(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)); pipe radius or duct half-width
(setq rc (+ r d)); center line bend radius
(setq p1 (getpoint "\n Start point: "))
(setq p2 (getpoint p1 "\n Next point: "))
(command "-layer" "m" "1" "")
(command "-layer" "m" "axes" "")
(command "-layer" "lt" "center" "" "")
(command "-layer" "c" "1" "" "")
(command "clayer" "1")
(command "line" p1 p2 ""); center line first segment
(setq cl1 (entlast))
(command "change" cl1 "" "p" "la" "axes" "" "")
(setq u1 (angle p1 p2))

(setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; first point = rd = right
(setq rd2 (polar rd1 u1 (distance p1 p2)))
(setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; first point = lu = left
(setq lu2 (polar lu1 u1 (distance p1 p2)))
(setvar "osmode" 0)
(command "line" rd1 lu1 ""); cross line = L=diameter
(command "line" rd1 rd2 ""); first line (right)
(setq erd (entlast)); first line
(command "line" lu1 lu2 ""); first line (left)
(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))
(command "line" p1 p2 "")
(setq cl (entlast))
(command "change" cl "" "p" "la" "axes" "" "")
(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 2))(setq u5 (- u5 (* pi 2))))
(if (< u5 0)(setq u5 (+ (* pi 2) u5))))
(command "line" rd2 lu2 "")
(command "_.undo" "end")
(setvar "osmode" osn)
(setvar "filletrad" ofr)
(princ)
)

Advertisements