
(defun dtr (a)
       (* pi (/ a 180))
                       )
(defun rtd (a)
       (/ (* a 180) pi)
                       )
(defun C:xx ()
       (setvar "cmdecho" 0)
       (setvar "cecolor" "50")
       (setvar "dimasz" 0)
       (setvar "dimtxt" 3)
       (setvar "dimgap" 2)
       (setq zone (getstring "\nEnter Zone name<A ... Z>:"
                                                                )
                                                                    )
       (setq ss (getint "\nEnter number of pipes:"
                                                      )
                                                           )
       (setq s 1)
       (while (<= s ss)
             (setq s1 (getint "\nEnter Pipe No.:"
                                                   )
                                                      )
             (if (> s 1) (setq z lastz)(setq z (getstring "\nEnter name of manhole:")  )      )
             (if (> s 1) (setq p lastp) (setq p (getpoint "\nPick Manhole:"         )  )      )
             (if (<= s 1)
                          (setq a1 (entsel "\nSelect 1st text:"       )      )   )
             (if (<= s 1)
                          (setq a2 (entsel "\nSelect 2nd text:"       )      )   )
             (if (<= s 1)
                         (if (= a1 nil) (alert "YOU HAVEN'T SELECT TEXT.") (setq b1 (car a1) ) )                        )
             (if (<= s 1)
                          (setq b2 (car a2)  )                        )
             (if (<= s 1)
                          (setq c1 (entget b1)      )                 )
             (if (<= s 1)
                          (setq c2 (entget b2)      )                 )
             (if (<= s 1)
                          (setq e1 (assoc '1 c1)    )                 )
             (if (<= s 1)
                          (setq e2 (assoc '1 c2)    )                 )
             (if (<= s 1)
                          (setq f1 (cdr e1)         )                 )
             (if (<= s 1)
                          (setq f2 (cdr e2)         )                 )
             (if (<= s 1)
                          (setq g1 (atof f1)        )                 )
             (if (<= s 1)
                          (setq g2 (atof f2)        )                 )
             (if (<= s 1)
                          (setq h1 (assoc '10 c1)   )                 )
             (if (<= s 1)
                          (setq h2 (assoc '10 c2)   )                 )
             (if (<= s 1)
                          (setq i1 (cdr h1)         )                  )
             (if (<= s 1)
                          (setq i2 (cdr h2)         )                  )
             (if (<= s 1)
                          (setq ang1 (cdr (assoc '50 c1)  )  )         )
             (if (<= s 1)
                          (setq ang2 (cdr (assoc '50 c2)  )  )         )
             (if (<= s 1)
                          (setq hei1 (cdr (assoc '40 c1)  )  )         )
             (if (<= s 1)
                          (setq hei2 (cdr (assoc '40 c2)  )   )        )
             (if (<= s 1)
                          (setq po1 (polar i1 ang1 (* 3.1 hei1)  )  )  )
            (if (<= s 1)
                          (setq po2 (polar i2 ang2 (* 3.1 hei2)  )  )  )
            (if (<= s 1)
                          (setq dist (/ (abs (- g1 g2)) (distance po1 po2)  )  )       )
            (if (<= s 1)
                          (if (< g1 g2) (setq t (+ (* (distance p po1) dist) g1)) (setq t (+ (* (distance p po2) dist) g2)  )  )  )
            (if (<= s 1)
                          (setq q (rtos t)) (setq q lastq)
                                                             )
            (setq z5 (strcat zone z)  )
            (setq z6 (read z)  )
                  (if (<= s 1) (command "dim1" "leader" p pause pause  z5) )
                  (if (<= s 1) (setq lastpo1 (getvar "lastpoint"))
                                                                      )
                  (if (<= s 1) (if (> (car lastpo1) (car p)) (setq eang1 0) (setq eang1 180) )
                             )
                  (if (<= s 1) (command "insert" "ellipse"  lastpo1 "" "" eang1
                                                 "donut" "0" "2" p "" )
                                )
                  (setq color5 (getvar "cecolor"))
                  (setvar "cecolor" "240")
                  (if (<= s 1) (command "circle" po1 "0.5"
                                                          "circle" po2 "0.5")
                                                                               )
                 (setvar "cecolor" color5)
                 (setq zz (getstring "\nEnter name of next manhole:"))
                 (if (> s 1) (setq out (getint "\nEnter pipe lenght (Enter for none):")))
                 (if (> s 1) (if (= out nil) (setq pp (getpoint "\nPick Manhole:")) (setq pp (polar p ang5 out))) (setq pp (getpoint "\nPick Manhole:"))  )
                 (setq z7 (strcat zone zz))
                 (setq z8 (read zz))
                 (command "dim1" "leader" pp pause pause  z7
                                                               )
                 (setq lastpo2 (getvar "lastpoint"))
                 (if (> (car lastpo2) (car pp)) (setq eang2 0) (setq eang2 180)
                                )
                 (command "insert" "ellipse" lastpo2 "" ""  eang2
                                   "donut" "0" "2" pp ""
                                                                 )
                 (setq aa1 (entsel "\nSelect 1st text:"))
                 (setq aa2 (entsel "\nSelect 2nd text:"))
                 (setq bb1 (car aa1))
                 (setq bb2 (car aa2))
                 (setq cc1 (entget bb1))
                 (setq cc2 (entget bb2))
                 (setq ee1 (assoc '1 cc1))
                 (setq ee2 (assoc '1 cc2))
                 (setq ff1 (cdr ee1))
                 (setq ff2 (cdr ee2))
                 (setq gg1 (atof ff1))
                 (setq gg2 (atof ff2))
                 (setq hh1 (assoc '10 cc1))
                 (setq hh2 (assoc '10 cc2))
                 (setq ii1 (cdr hh1))
                 (setq ii2 (cdr hh2))
                 (setq angle1 (cdr (assoc '50 cc1)))
                 (setq angle2 (cdr (assoc '50 cc2)))
                 (setq heig1 (cdr (assoc '40 cc1)))
                 (setq heig2 (cdr (assoc '40 cc2)))
                 (setq poi1 (polar ii1 angle1 (* 3.1 heig1)))
                 (setq poi2 (polar ii2 angle2 (* 3.1 heig2)))
                 (setq dista (/ (abs (- gg1 gg2)) (distance poi1 poi2)))
                 (if (< gg1 gg2) (setq tt (+ (* (distance pp poi1) dista) gg1)) (setq tt (+ (* (distance pp poi2) dista) gg2)) )
                 (setq qq (rtos tt))
                 (setq j (open "data.dat" "a"))
                 (setq uu1 (+ (distance p pp) 0.5))
                 (setq y (list s1 z6 z8 (fix uu1) (+ (atof q) 1800) (+ (atof qq) 1800)))
                 (print y j)
                 (Close j)
                 (command "line" p pp "")
                 (setq ang5 (angle p pp))
                 (setq dist5 (/ (distance p pp) 2))
                 (setq pt1 (polar p ang5 dist5))
                 (if (< (rtd ang5) 90) (setq ang6 (+ (rtd ang5) 90)) (if (< (rtd ang5) 270) (setq ang6 (- (rtd ang5) 90)) (setq ang6 (+ (rtd ang5) 90))))
                 (setq pt2 (polar pt1 (dtr ang6) 2))
                 (setq color2 (getvar "cecolor"))
                 (if (< (rtd ang5) 90) (setq ang10 (angle p pp)) (if (< (rtd ang5) 270) (setq ang10 (angle pp p)) (setq ang10 (angle p pp))))
                 (setvar "cecolor" "240")
                 (command "text" pt2 "3" (rtd ang10) s1 "")
                 (command "circle" poi1 "0.5"
                          "circle" poi2 "0.5"
                                                 )
                 (setvar "cecolor" color2)
                 (command "insert" "wblock"  (polar p ang5 (- dist5 4)) "" "" (rtd ang5))
                 (setq lastz zz)
                 (setq lastp pp)
                 (setq lastq qq)
                 (setq s (+ 1 s))
                                        );END WHILE
                 (setvar "dimasz" 1.5)
                 (setvar "cmdecho" 1)
                                         );END DEFUN



(defun c:qq ()
       (setq p 0)
       (while (and (/= p 1) (/= p 2) (/= p 3) (/= p 4))
              (setq p (getint "\nEnter the area's name(1 2 3 4):"))
                                                                      )
       (setq n (getint "\nEnter the pipe number:"))
       (setq k (getpoint "\nEnter insertaion point of Area text:"))
       (command "area" pause pause pause pause pause pause "")
       (setq f (open "area.dat" "a"))
       (setq z (getvar "area"))
       (setq e (fix (+ z 0.5)))
       (if (= p 1) (setq m (list n e 0 0 0))
                    (if (= p 2) (setq m (list n 0 e 0 0))
                                   (if  (= p 3) (setq m (list n 0 0 e 0))
                                                  (setq m (list n 0 0 0 e)))
                                               )
                                                 )

       (setq v (rtos z))
       (command "text" k "3" "0" v "")
       (print m f)
       (close f)
                 );END DEFUN

(defun c:ww ()
              (setq o (getint "\nEnter the pipe number:"))
              (setq l (open "area.dat" "a"))
              (setq s (list o 0 0 0 0))
              (print s l)
              (close l)
                       );END DEFUN








