;;By Andrea Andreetti 2008-10-20 ;;
;; ;;
;; D R A I N C O N N E C T ;;
;; ;;
;;
(vl-load-com)
(defun c:DrainConnect (/ dr_sel1 dr_sel1data p1 SDrain_10 SDrain_11)

;; Degre to Radian ;;
;;
(defun dtr (a)
(* pi (/ a 180.0))
)
;;
;; Degre to Radian ;;

;; Language Detection ;;
;;
(if (vl-string-search "(FR)" (strcase (ver)))
(progn
(setq qstion0 "\nCommande: DrainConnect -Activй")
(setq qstion1 "\nDйbut du Drain: ")
)
(progn
(setq qstion0 "\nCommand: DrainConnect -Activated")
(setq qstion1 "\nSelect start point of Drain: ")
)
)
;;
;; Language Detection ;;

;; Selection and Data operation ;;
;;
(setq dr_sel1 nil)
(while (or (= dr_sel1 nil)
(/= (cdr (assoc 0 (setq dr_sel1data (entget (car dr_sel1))))) "LINE"))
(progn
(princ qstion1)
(setq dr_sel1 (entsel))
)
)
(setq p1 (osnap (cadr dr_sel1) "_near"))
(setq SDrain_10 (cdr (assoc 10 dr_sel1data)))
(setq SDrain_11 (cdr (assoc 11 dr_sel1data)))
;;
;; Selection and Data operation ;;

;; Units detection for ZY and ZY2 variables ;;
;;
(if (< (getvar "LUNITS") 3)
(setq zy 100)
(setq zy 4)
)
(setq zy2 (/ zy 2))
;;
;; Units detection for ZY and ZY2 variables ;;

;; PREVIEW MODE ;;
;;
(simulDrainAttach)
;;
;; PREVIEW MODE ;;

)
;;
;; ;;
;; D R A I N C O N N E C T ;;
;; ;;

;; ;;
;; S I M U L D R A I N A T T A C H ;;
;; ;;
;;
(defun simuldrainattach (/ #elp agp1 pstart1 pstart2 pointtomod ndrainent)

(while (= (car (setq grr (grread t 2))) 5)
(redraw)
(grdraw p1 (polar p1 (dtr 0) zy2) 52 1)
(grdraw p1 (polar p1 (dtr 45) zy2) 52 1)
(grdraw p1 (polar p1 (dtr 90) zy2) 52 1)
(grdraw p1 (polar p1 (dtr 135) zy2) 52 1)
(grdraw p1 (polar p1 (dtr 180) zy2) 52 1)
(grdraw p1 (polar p1 (dtr 225) zy2) 52 1)
(grdraw p1 (polar p1 (dtr 270) zy2) 52 1)
(grdraw p1 (polar p1 (dtr 315) zy2) 52 1)
(setq #elp (car (cdr grr)))
(setq agp1 (inters #elp
(polar #elp (+ (angle sdrain_11 sdrain_10) (dtr 90)) 2.0)
sdrain_10
sdrain_11
nil
)
)
(if (not agp1)
(setq agp1 (inters #elp
(polar #elp (+ (angle sdrain_10 sdrain_11) (dtr 90)) 2.0)
sdrain_10
sdrain_11
nil
)
)
)
(setq pstart1 (polar agp1 (angle agp1 p1) zy))
(setq pstart2 (polar agp1 (angle agp1 #elp) zy))
(grdraw pstart1 pstart2 141 1)
(grdraw pstart2 #elp 141 1)
)
(if (eq (car grr) 3)
(progn (if (and pstart1 pstart2 #elp)
(vl-cmdf "._line" pstart1 pstart2 #elp "")
)
(redraw)
(if (not (inters pstart2
(polar pstart2
(angle pstart2 pstart1)
(+ (distance pstart2 pstart1) 2)
)
sdrain_10
sdrain_11
t
)
)
(progn (if (< (distance pstart1 sdrain_10)
(distance pstart1 sdrain_11)
)
(setq pointtomod 10)
(setq pointtomod 11)
)
(setq dr_sel1data (subst (cons pointtomod pstart1)
(assoc pointtomod dr_sel1data)
dr_sel1data
)
)
(setq dr_sel1data (entmod dr_sel1data))
(setq SDrain_10 (cdr (assoc 10 dr_sel1data)))
(setq SDrain_11 (cdr (assoc 11 dr_sel1data)))
)
)
(simuldrainattach)
)
(progn (redraw) (exit)(princ))
)
)
;;
;; ;;
;; S I M U L D R A I N A T T A C H ;;
;; ;;

;;======================================;;
;; AUTO-LOAD ;;
;;======================================;;
(princ
qstion0)

(c:DrainConnect)

Advertisements