(defun c:z () (command "zoom"))
(defun c:zw () (command "zoom" "w"))
(defun c:ze () (command "zoom" "e"))
(defun c:zp () (command "zoom" "p"))
(defun c:za () (command "zoom" "a"))
(defun c:f () (command "fillet" "r" "0" "fillet"))

(defun c:r () (command "rotate"))
(defun c:of () (command "offset"))
(defun c:t () (command "trim" ))
(defun c:et () (command "extend"))
(defun c:ex () (command "explode"))
(defun c:p () (command "pan"))

(defun c:i () (command "insert"))
(defun c:b () (command "block"))
(defun c:w () (command "wblock"))
(defun c:v () (command "view"))
(defun c:l () (command "line"))
(defun c:br () (command "break"))

(defun c:ci () (command "circle"))
(defun c:ch () (command "change"))
(defun c:mi () (command "mirror"))
(defun c:li () (command "list"))
(defun c:m () (command "move"))
(defun c:tx () (command "text"))

(defun c:la () (command "layer"))
(defun c:c () (command "copy"))
(defun c:dd () (command "ddedit"))

(defun c:arrow () (command "insert" "arrow"))
(defun c:dt () (command "dtext"))

(defun c:a () (command "array"))

(defun c:e () (command "erase"))

(defun c:ar () (command "area"))
(defun c:di () (command "dist"))

(defun c:sc () (command "scale"))
(defun c:cha () (command "chamfer"))

(defun c:c4 () (command "chamfer" "d" "4.573" "4.573" "chamfer"))


(defun c:zc () (command "zoom" "c"))

(defun c:arrow () (command "insert" "arrow"))
(defun c:z () (command "zoom"))
(defun c:ed () (load"ed") (c:ed))
(defun c:l= () (command "layer" "on"))
(defun c:l- () (command "layer" "off"))
(defun c:ls () (command "layer" "s"))
(defun c:lm () (command "layer" "m"))
(defun c:s () (command "save"))
(defun c:qy () (command "quit"))
(defun c:crd () (load"crd") (c:crd))
(defun c:pe () (command "pedit"))
(defun c:oe () (command "osnap" "end"))
(defun c:oi () (command "osnap" "int"))
(defun c:o- () (command "osnap" "off"))


(defun C:wrt()
  (if (= scale nil)
    (setq scale ( getreal "\n Enter scale of plan, 1: "))
  )
  (setq fac (/ scale 1000.0))
  (prompt "\n 1-coordinates  2-Old Lot & PA  3-Adj. PA  4-Field Book")
  (setq choice (getint "\nEnter choice "))
  (if (= done nil) (setDMS))
  (if (= choice 1) (wrCo) )
  (if (= choice 2) (wrOPA) )
  (if (= choice 3) (wrAPA) )
  (if (= choice 4) (wrFB) )
)

(defun ToDecD(brgdms)
      ; added on 17/12/97 stment below
      (setq brgdms (+ brgdms 0.000001))	
      (setq wbrg (fix brgdms))
      (setq ms (- brgdms wbrg))
      (setq min (* ms 100.0))
      (setq wmin (fix min))
      (setq sec (- min wmin))
      (setq sec (* sec 100.0))
      (setq sec (/ sec 60.0))
      (setq min (+ wmin sec))
      (setq min (/ min 60.0))
      (+ wbrg min)
)


(defun c:PlotP ()

  ;(command "osnap" "cen")
  ;(graphscr)
  ;(setq pi 3.14159)
  ;(setq pt1 (list 1,1))
  (setq pt1 (getpoint "\nReference point: "))
  (while (/= pt1 nil)
    (command "osnap" "none")
    (setq Sbg (getstring "\nEnter bearing: "))
    (while (/= Sbg "")
      (setq brgdms (atof Sbg))
      (setq brg (ToDecD brgdms))
      (setq dis (getreal "\nEnter distance: "))
      (setq brg (- 90.0 brg)) ;9/1/92 closewise from East
      (setq brg1 (/ brg 180.0))
      (setq brg2 (* brg1 pi))
      (setq pt3 (polar pt1 brg2 dis))
      (command "point" pt3)
      (setq Sbg (getstring "\nEnter bearing: "))
    )
      ;(command "osnap" "cen")
      (setq pt1 (getpoint "\nReference point: "))
  )
)

(defun c:PlotL ()
  (setq pt1 (getpoint "\nReference point: "))
  (while (/= pt1 nil)
    (command "osnap" "none")
    (setq Sbg (getstring "\nEnter bearing: "))
    (while (/= Sbg "")
      (setq brgdms (atof Sbg))
      (setq brg (ToDecD brgdms))
      (setq dis (getreal "\nEnter distance: "))
      (setq brg (- 90.0 brg)) ;9/1/92 closewise from East
      (setq brg1 (/ brg 180.0))
      (setq brg2 (* brg1 pi))
      (setq pt3 (polar pt1 brg2 dis))
      (command "Line" pt1 pt3 "")
      (setq Sbg (getstring "\nEnter bearing: "))
    )
      ;(command "osnap" "cen")
      (setq pt1 (getpoint "\nReference point: "))
  )
)

(defun c:PlotT ()

  (setq pt1 (getpoint "\nStart point: "))
  (while (/= pt1 nil)
    (command "osnap" "none")
    (setq Sbg (getstring "\nEnter bearing: "))
    (while (/= Sbg "")
      (setq brgdms (atof Sbg))
      (setq brg (ToDecD brgdms))
      (setq dis (getreal "\nEnter distance: "))
      (setq brg (- 90.0 brg)) ;9/1/92 closewise from East
      (setq brg1 (/ brg 180.0))
      (setq brg2 (* brg1 pi))
      (setq pt3 (polar pt1 brg2 dis))
      (command "Line" pt1 pt3 "")
      (setq pt1 pt3)
      (setq Sbg (getstring "\nEnter bearing: "))
    )
      ;(command "osnap" "cen")
      (setq pt1 (getpoint "\nReference point: "))
  )
)



(defun setdecD()
  (command "Units" 2 3 1 5 270 "y") ; dist in decimal, 1 decimal place, angel in
  (command "graphscr")              ; decimal deg
)
				
(defun setDMS()
  (command "Units" 2 3 2 5 270 "y") ; dist in decimal, 3 decimal place, angel in dms
  (command "graphscr")              ; d m s
  (setq done 1)
)


(defun wrCo()
  ;(setq fac (/ scale 1000.0))
  (setq ht (* 1.8 fac ))
  (setq num (getint "\nEnter decimal places for coordinates: <1> "))
  (if (= num nil) (setq num 1))
  (if (< num 1) (setq num 1))
  (if (> num 3) (setq num 3))

  (command "Units" 2 num 2 5 270 "y") ; dist in decimal, 3 decimal place, angel in dms
  (command "graphscr")
  (setq pt1 (list 1000.0 1000.0))
  (setq pt1 (getpoint "\nPick the required point: "))
 (while (not(equal pt1 nil))
  (setq pt2 (getpoint "\nLocate point for writing text: "))
  (setq x (car pt1))
  (setq y (cadr pt1))
  (setq ax (abs x))
  (setq ay (abs y))
  (if (>= x 0.0)
    (setq x (strcat "T " (rtos ax)))
    (setq x (strcat "B " (rtos ax)))
  )
  (if (>= y 0.0)
    (setq y (strcat "U " (rtos ay)))
    (setq y (strcat "S " (rtos ay)))
  )
  (command "layer" "s" "FRAME" "")
  (command "text" pt2 ht "90d" y)
  (command "text" "" x)
  (setq pt1 (getpoint "\nPick the required point: "))
 )
  (setDMS)
)


(defun getpt1()
  (setq pt1 (getpoint "\nLocate point for writing text. "))
)

(defun wrOPA()

  (setq ht (* 3.2 fac ))
  (getpt1)
  (setq s1 (getstring "\nEnter old lot no: "))
  (setq s2 (getstring "\nEnter old PA no: "))
  (setq x (car pt1))
  (setq y (cadr pt1))
  (command "layer" "s" "LOTNO" "")
  (if (= done nil) (setDMS))
  (command "text" pt1 ht "90d" s1)
  (setq ht (* 1.8 fac))
  (setq x (+ x (* 1.5 fac)))
  (setq y (- y (* 4.0 fac)))
  (setq pt2 (list x y))
  (command "layer" "s" "LOT" "")
  (command "text" pt2 ht "90d" s2)
)

(defun wrFB()

  (setq ht (* 1.8 fac))
  (getpt1)
  (setq s1 (getstring "\nField book no: "))
  (setq s2 (getstring "\nEnter page no: "))
  (setq s1 (strcat "BK " s1))
  (setq x (car pt1))
  (setq y (cadr pt1))
  (setq ht (* 1.8 fac))
  (setq gap (* 1.0 fac))
  (command "layer" "s" "FRAME" "")
  (if (= done nil) (setDMS))
  (command "text" pt1 ht "90d" s1)
  (setq leng (* ht (- (strlen s1) 1)))
  (setq leng (* leng 0.785))
  ;(setq leng (+ leng gap))

  (setq x1  x )
  (setq x2 (+ x leng))
  (setq y1 (- y gap))
  (setq pt1 (list x1 y1))
  (setq pt2 (list x2 y1))
  (command "line" pt1 pt2 "")
  (setq x1 (* (+ x1 x2) 0.5))
  (setq x1 (- x1 ht))
  (setq y1 (- y1 (* 2.8 fac)))
  (setq pt1 (list x1 y1))
  (command "text" pt1 ht 90.0 s2)
)

(defun wrAPA()
  (setq ht (* 2.5 fac))
  (getpt1)
  (setq s1 (getstring "\nEnter PA no. for adj. plan: "))
  (setq x (car pt1))
  (setq y (cadr pt1))
  (setq s1 (strcat "Lihat PA " s1))
  (command "layer" "s" "FOOTNOTE" "")
  (if (= done nil) (setDMS))
  (command "text" pt1 ht "90d" s1)
)

(defun init()
  (setq set1 nil)
  (setq type 0)
  (setq scale (getreal "Enter scale 1: "))
  (while (or (< type 1 ) (> type 6))
    (setq type (getint "Enter plan format:  A2 Size: 1=AA 2=BB 3=CC   A3 Size: 4=A 5=B 6=C  "))
  )

  (setq fac (/ scale 1000.0))
  (setq wf 0.785)

)
(defun openfile()
  (while (= Infile nil)
    (setq Infile1 (getstring "\nName of data file (.HED): "))
    (setq InFile1 (strcat Infile1 ".HED"))
    (setq Infile (open Infile1 "r"))
    (if (= Infile nil)
      (prompt "\Unable to open file: ")
      (prompt "\File opened: ")
    )
    (prompt infile1)
  )
)

(defun setpos (type)
  (if (> type 3)
    (setq tht (* 2.2 fac))
    (setq tht (* 2.5 fac))
  )
  (if (= type 1)
    (progn
      (setq x sx)
      ;(setq y (- sy (* 145.0 fac )))
      (setq y (- sy (* 131.5 fac )))
      (setq ygap (* 8.5 fac))
    )
  )
  (if (= type 2)
    (progn
      (setq x sx)
      ;4/1/2000 (setq y (- sy (* 222.0 fac )))
      (setq y (- sy (* 215.5 fac )))
      (setq ygap (* 8.5 fac))
    )
  )

  (if (= type 3)
    (progn
      (setq x (- sx (* 140.0 fac )))
      ;6/1/2000
      ;(setq x (- sx (* 120.0 fac )))
      (setq y (- sy (* 2.5 fac )))
      (setq ygap (* 15.0 fac))
    )
  )
  (if (= type 4)
    (progn
      (setq x sx)
      (setq y (- sy (* 100.0 fac )))
      (setq ygap (* 6.0 fac))
    )
  )
 (if (= type 5)
    (progn
      (setq x sx)
      (setq y (- sy (* 150.0 fac )))
      (setq ygap (* 6.0 fac))
    )
 )
 (if (= type 6)
    (progn
      (setq x (- sx (* 100.0 fac )))
      (setq y (- sy (* 2.2 fac )))
      (setq ygap (* 6.0 fac))
    )
 )
)

(defun rou10(x)
    (command "Units" 2 0 1 5 270 "y")
    (if ( > x 0)
      (setq tmp 10.0)
      (setq tmp 0.0)
    )
    ( + tmp (* 10 (fix (/ x 10.0))))
)

(defun rouN(x n)
    (command "Units" 2 0 1 5 270 "y")
    ;(setq px (abs x))
    (if ( > x 0)
      (setq tmp n)
      (setq tmp 0.0)
    )
    (setq px (* n (fix (/ x n))))
    (if (= px x)
      (setq tmp 0.0)
    )
    ( + tmp (* n (fix (/ x n))))
)

(defun C:grids()

  (setq oldech (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
   (init)

   (openfile)

   ;(setq delta (* 100.0 fac))
   (setq th (* 1.8 fac))
   ;(setq baki (getstring "\nBAKI LOT: "))
   (setq pa (getstring "\nNo PA: "))

   (command "osnap" "int")
   (setq pt (getpoint "\nPick the lower left corner of frame: "))
   (setq x1 (car pt))
   (setq y1 (cadr pt))
   (command "osnap" "none")
   (command "Units" 2 3 1 5 270 "y")

   (command "Layer" "M" "ConLine" "c" "White" "ConLine" "lt" "Dashed" "ConLine" "")
   (command "Layer" "M" "Frame" "c" "yellow" "Frame" "lt" "Continuous" "Frame" "")
   (command "Layer" "M" "Title" "c" "red" "Title" "")
   (command "Layer" "M" "CPNO" "C" "cyan" "CPNO" "")
   (command "Layer" "M" "MarkText" "C" "Yellow" "MarkText" "")
   (Command "Layer" "M" "FootNote" "C" "green" "FootNote" "Lt" "CONTINUOUS" "FootNote" "")
   (command "Layer"  "S" "FRAME" "")

   (setq gap (* fac 100.0))
   (setq ti (* 5.0 fac))
   (setq xgap (* 5.0 fac))
   (setq ygap (* 5.0 fac))
   (if (< xgap 5.0)
    (setq xgap 5.0)
   )
   (if (< ygap 5.0)
    (setq ygap 5.0)
   )
   ;(setq xgap (* 10.0 fac)) 8/10/99
   ;(setq ygap (* 10.0 fac))

   (cond
     ( (= type 1)
       (setq xext 440.0) ;460.0)
       (setq yext 380.0) ;400.0)
       (setq side "r")
     )

     ( (= type 2)
       (setq xext 260.0) ;280.0)
       (setq yext 554.0) ;560.0)
       (setq side "l")
     )

     ( (= type 3)
       (setq xext 554.0) ;560.0)
       (setq yext 260.0) ;280.0)
       (setq side "l")
     )

     ( (= type 4)
       (setq xext 310.0)
       (setq yext 270.0)
       (setq side "r")
     )

     ( (= type 5)
       (setq xext 190.0)
       (setq yext 390.0)
       (setq side "l")
     )

     ( (= type 6)
       (setq xext 390.0)
       (setq yext 190.0)
       (setq side "l")
     )	
   )

   (setq x2 (+ x1 (* xext fac)))
   (setq y2 (+ y1 (* yext fac)))
   (setq delta (* 100.0 fac))
   (cond
     ( (= type 1)
       (setq sx (- x1 (* 114.0 fac)))
       (setq sy y2)
     )
     ( (= type 2)
       (setq sx (+ x2 (* 6.0 fac)))
       (setq sy y2)
     )
     ( (= type 3)
       (setq sx (- x2 (* 140.0 fac)))
       (setq sy (- y1 (* 14.0 fac)))
     )

     ( (= type 4)
       (setq sx (- x1 (* 80.0 fac)))
       (setq sy y2)
     )
     ( (= type 5)
       (setq sx (+ x2 (* 6.0 fac)))
       (setq sy y2)
     )
     ( (= type 6)
       (setq sx (- x2 (* 85.0 fac)))
       (setq sy (- y1 (* 5.0 fac)))
     )
   )

   (setq n 10) ; default
   (cond
     ( (<= scale 200)
       (setq n 20)
       ;(setq delta n)
     )
     ( (= scale 250)
       (setq n 25)
       ;(setq delta n)
     )
     ( (= scale 400)
        (setq n 20)
       ;(setq delta n)
     )
     ( (= scale 500)
       (setq n 50)
       ;(setq delta n)
     )

     ( (= scale 750)
       (setq n 50)
     )
     ( (= scale 800)
       (setq n 20)
       ;(setq delta n)
     )

     ( (>= scale 1000)
       (setq n 100)
     )
   )

   (setq x (+ x1 xgap))
   (setq x (rouN x n))
   (setq j (rem x 100))
   (cond
     ( (= scale 400)
       (if (= j 40)
        (setq x (+ x 20))
       )
       (if (= j 80)
        (setq x (+ x 20))
       )
       (if (= j -20)    ; (= j -60))
        (setq x (+ x 20))
       )
       (if (= j -60)
        (setq x (+ x 20))
       )
    )
    ( (= scale 800)
       (if (= j 60)
        (setq x (+ x 40))
       )
       (if (= j 80)
        (setq x (+ x 20))
       )
       (if (= j -20)
        (setq x (+ x 20))
       )
       (if (= j -40)
        (setq x (+ x 40))
       )
     )
   )


   (setq sc (rtos scale))
   (setq y y1)
   (while (< x x2)
     (if (>= x x1)
       (progn
	 (setq pt1 (list x y))
	 (setq pt2 (list x y2))
	 (setq y1a (+ y ti))
	 (setq y2a (- y2 ti))
	 (setq pt1a (list x y1a))
	 (setq pt2a (list x y2a))
	 (command "line" pt1 pt1a "")
	 (command "line" pt2 pt2a "")
	 (wrtx x y)
       )
     )
     (setq x (+ x delta))
     ; annotate
   )

   (setq x x1)
   (setq y (+ y1 ygap))
   (setq y (rouN y n))
   (setq j (rem y 100))

   (cond
     ( (<= scale 400)
       (if (= j 40)
        (setq y (+ y 20))
       )
       (if (= j 80)
        (setq y (+ y 20))
       )
       (if (= j -20)    ; (= j -60))
        (setq y (+ y 20))
       )
       (if (= j -60)
        (setq y (+ y 20))
       )
    )
    ( (= scale 800)
       (if (= j 60)
        (setq y (+ y 40))
       )
       (if ( = j 80)
        (setq y (+ y 20))
       )
       (if ( = j -20)
        (setq y (+ y 20))
       )
       (if (= j -40)
        (setq y (+ y 40))
       )
     )
   )

   (while (< y y2)
     (if (>= y y1)
       (progn
	 (setq pt1 (list x y))
	 (setq pt2 (list x2 y))
	 (setq x1a ( + x ti))
	 (setq x2a ( - x2 ti))
	 (setq pt1a (list x1a y))
	 (setq pt2a (list x2a y))
	 (command "line" pt1 pt1a "")
	 (command "line" pt2 pt2a "")

	 (if (= type 1)
	   (wrty x2 y side)
	 )
	 (if (= type 3)
	   (wrty x1 y side)
	 )
	 (if (= type 2)
	   (wrty x1 y side)
	 )

	 (if (= type 4)
	   (wrty x2 y side)
	 )
	 (if (= type 6)
	   (wrty x1 y side)
	 )
	 (if (= type 5)
	   (wrty x1 y side)
	 )

       )
     )
     (setq y (+ y delta))
   )

   ; plot north pt and write heading

   (command "Units" 2 3 1 5 270 "y")
   (if (< type 4)
     (wrhead sx sy type)
     (wrheada3 sx sy type)
   )
   ;(if (= type 2)
   ;  (wrhead sx sy type)
   ;)
   ;(if (= type 3)
   ;  (wrhead sx sy type)
   ;)

   ;(if (= type 4)
   ;  (wrheada3 sx sy type)
   ;)
   ;(if (= type 5)
   ;  (wrheada3 sx sy type)
   ;)
   ;(if (= type 6)
   ;  (wrheada3 sx sy type)
   ;)
   (setvar "CMDECHO" oldech)
   (command "Units" 2 3 2 5 270 "y")
   ; bearing in deg min sec
   (command "Graphscr")

)


(defun wrheada3(sx sy type)
  (setq npl (* 56.0 fac))
  (setq slt1 (* 15.0  fac))
  (setq slt2 (* 4.05  fac))
  (setq srt (* 3.0 fac))
  ;Plot north point symbol
  (command "Layer" "s" "FootNote" "")
  (command "Osnap" "none")
  (setq pt (list sx sy))
  (command "Line"
    pt
    (strcat "@" (rtos npl) "<180.0")
    ""
  )
  (command "Line"
    pt
    (strcat "@" (rtos slt1) "<170.0")
    (strcat "@" (rtos slt2) "<220.0")
    ""
  )
  (setq x (- sx (* 0.5 srt)))
  (setq y (- sy (* 30.0 fac)))
  (setq pt (list x y))
  (command "Line"
    pt
    (strcat "@" (rtos srt) "<90.0")
    ""
  )


  ;Write heading
  (command "Layer" "s" "Title" "")
  ;(setq scale 1000.0)
  (setq ygap (* 10.0 fac))
  (setq x (+ sx (* 9.0 fac)))    ;(- sx (* 114.0 fac)))
  (setq y (- sy (* 4.0 fac)))
  (setq tht (* 4.0 fac))
  (setq brg 90.0)

  (setq data1 (read-line Infile))
  (setq n 1)
  (wrtext x y tht brg data1)
  (setq y (- y ygap))
  (while (/= data1 nil)
    (setq data1 (read-line Infile))
    (setq n (1+ n))
    (if (/= data1 nil)
      (progn
	(if (= n 6)
	  (progn
	  (setq y (+ y (* 3.0 fac)))
	  (setq tht (* 2.2 fac))
	  )
	)
	(if (= n 7)
	  (progn
	  (setq y (+ y (* 3.0 fac)))
	  (setq tht (* 2.2 fac))
	  )
	)

	(if ( > n 5 )
	  (command "Layer" "s" "FootNote" "" )
	)

	(setq sstr (substr data1 1 3))
	(if (/= sstr "NOS")
	  (progn
	    (wrtext x y tht brg data1)
	    (setq y (- y ygap))
	  )
	)
	(if (= n 7)
	  (setpos type)
	)
      )
    )
  )
  (close Infile)


  (if (= type 4)
    (progn
      ;6/1/2000 (setq y (+ y1 (* 50.0 fac ))) ; 210
      (setq y (+ y1 (* 40.0 fac ))) ; 210
      ;(setq y (+ y1 (* 50.0 fac )))
      (setq ygap (* 25.0 fac))
     )
  )
  (if (= type 5)
    (progn
      ;6/1/2000 (setq y (+ y1 (* 50.0 fac ))) ; 210
      (setq y (+ y1 (* 40.0 fac ))) ; 210
      (setq ygap (* 25.0 fac))
     )
  )

  (if (= type 6)
    (progn
      (setq x x1)
      ;4/1/2000 (setq y (- y1 (* 25.0 fac )))
      (setq y (- sy (* 2.2 fac )))
      (setq ygap (* 25.0 fac))
    )
  )
  ;(wrtext x y tht brg "Dicarta Oleh")
  ;(setq y (- y ygap))


  ;2/11/99 (wrtext x y tht brg "Diperiksa Oleh")
  ;(setq y (- y ygap))

  (wrtext x y tht brg "Diluluskan Oleh")

  (if (= type 4)
    (setq y y1)
  )
  (if (= type 5)
    (setq y y1)
  )

  (if (= type 6)
    (progn
      ;20-11-1997
      (setq y (- y1 (* 80 fac)))
      ;(setq y (- y (* 43.5 fac))) ;46.0
    )
  )

  (setq tht (* 6.0 fac))
  (command "Layer" "s" "CPNO" "")
  (wrtext x y tht brg (strcat "PA " pa))
)

(defun C:gridsOld()

  (setq oldech (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
      (init)

   (openfile)

   ;(setq delta (* 100.0 fac))
   (setq th (* 1.8 fac))
   ;(setq baki (getstring "\nBAKI LOT: "))
   (setq pa (getstring "\nNo PA: "))

   (command "osnap" "int")
   (setq pt (getpoint "\nPick the lower left corner of frame: "))
   (setq x1 (car pt))
   (setq y1 (cadr pt))
   (command "osnap" "none")
   (command "Units" 2 3 1 5 270 "y")

   (command "Layer" "M" "ConLine" "c" "White" "ConLine" "lt" "Dashed" "ConLine" "")
   (command "Layer" "M" "Frame" "c" "yellow" "Frame" "lt" "Continuous" "Frame" "")
   (command "Layer" "M" "Title" "c" "red" "Title" "")
   (command "Layer" "M" "CPNO" "C" "cyan" "CPNO" "")
   (Command "Layer" "M" "FootNote" "C" "green" "FootNote" "Lt" "CONTINUOUS" "FootNote" "")


   (command "Layer"  "S" "FRAME" "")
   (setq gap (* fac 100.0))
   (setq ti (* 5.0 fac))
   (setq xgap (* 10.0 fac))
   (setq ygap (* 10.0 fac))
   ;(if (< xgap 10.0)
   ;  (setq xgap 10.0)
   ;)
   ;(if (< ygap 10.0)
   ;  (setq ygap 10.0)
   ;)


   (cond
     ( (= type 1)
       (setq xl 460.0)
       (setq yl 400.0)
       (setq side "r")
     )


     ( (= type 2)
       (setq xl 280.0)
       (setq yl 560.0)
       (setq side "l")
     )

     ( (= type 3)
       (setq xl 560.0)
       (setq yl 280.0)
       (setq side "l")
     )
   )

   (setq x2 (+ x1 (* xl fac)))
   (setq y2 (+ y1 (* yl fac)))
   (setq delta (* 100.0 fac))
   (cond
     ( (= type 1)
       (setq sx (- x1 (* 114.0 fac)))
       (setq sy y2)
     )
     ( (= type 2)
       (setq sx (+ x2 (* 6.0 fac)))
       (setq sy y2)
     )
     ( (= type 3)
       (setq sx (- x2 (* 140.0 fac)))
       (setq sy (- y1 (* 14.0 fac)))
     )
   )

   (setq n 10) ; default
   (cond
     ( (<= scale 200)
       (setq n 20)
       ;(setq delta n)
     )
     ( (= scale 250)
       (setq n 25)
       ;(setq delta n)
     )
     ( (= scale 400)
        (setq n 20)
       ;(setq delta n)
     )
     ( (= scale 500)
       (setq n 50)
       ;(setq delta n)
     )

     ( (= scale 750)
       (setq n 50)
     )
     ( (= scale 800)
       (setq n 20)
       ;(setq delta n)
     )

     ( (>= scale 1000)
       (setq n 100)
     )
   )

   (setq x (+ x1 xgap))
   (setq x (rouN x n))
   (setq j (rem x 100))
   (cond
     ( (= scale 400)
       (if (= j 40)
        (setq x (+ x 20))
       )
       (if (= j 80)
        (setq x (+ x 20))
       )
       (if (= j -20)    ; (= j -60))
        (setq x (+ x 20))
       )
       (if (= j -60)
        (setq x (+ x 20))
       )
    )
    ( (= scale 800)
       (if (= j 60)
        (setq x (+ x 40))
       )
       (if (= j 80)
        (setq x (+ x 20))
       )
       (if (= j -20)
        (setq x (+ x 20))
       )
       (if (= j -40)
        (setq x (+ x 40))
       )
     )
   )


   (setq sc (rtos scale))
   (setq y y1)
   (while (< x x2)
     (if (>= x x1)
       (progn
	 (setq pt1 (list x y))
	 (setq pt2 (list x y2))
	 (setq y1a (+ y ti))
	 (setq y2a (- y2 ti))
	 (setq pt1a (list x y1a))
	 (setq pt2a (list x y2a))
	 (command "line" pt1 pt1a "")
	 (command "line" pt2 pt2a "")
	 (wrtx x y)
       )
     )
     (setq x (+ x delta))
     ; annotate
   )

   (setq x x1)
   (setq y (+ y1 ygap))
   (setq y (rouN y n))
   (setq j (rem y 100))

   (cond
     ( (<= scale 400)
       (if (= j 40)
        (setq y (+ y 20))
       )
       (if (= j 80)
        (setq y (+ y 20))
       )
       (if (= j -20)    ; (= j -60))
        (setq y (+ y 20))
       )
       (if (= j -60)
        (setq y (+ y 20))
       )
    )
    ( (= scale 800)
       (if (= j 60)
        (setq y (+ y 40))
       )
       (if ( = j 80)
        (setq y (+ y 20))
       )
       (if ( = j -20)
        (setq y (+ y 20))
       )
       (if (= j -40)
        (setq y (+ y 40))
       )
     )
   )

   (while (< y y2)
     (if (>= y y1)
       (progn
	 (setq pt1 (list x y))
	 (setq pt2 (list x2 y))
	 (setq x1a ( + x ti))
	 (setq x2a ( - x2 ti))
	 (setq pt1a (list x1a y))
	 (setq pt2a (list x2a y))
	 (command "line" pt1 pt1a "")
	 (command "line" pt2 pt2a "")

	 (if (= type 1)
	   (wrty x2 y side)
	 )
	 (if (= type 3)
	   (wrty x1 y side)
	 )
	 (if (= type 2)
	   (wrty x1 y side)
	 )
       )
     )
     (setq y (+ y delta))
   )

   ; plot north pt and write heading

   (command "Units" 2 3 1 5 270 "y")
   (wrhead sx sy type)
   (setvar "CMDECHO" oldech)
   (command "Units" 2 3 2 5 270 "y")
   ; bearing in deg min sec
   (command "Graphscr")

)


(defun tostr(x)
  (setq str (rtos x))
   (setq sl (strlen str))
   (if (< x 0.0)
     (setq str (substr str 2 (- sl 1)))
     (setq str str)
  )
)

(defun wrtx(x y)
   (setq th1 (* 1.8 fac))       
   (setq strx (tostr x))
   (if (< x 0.0)
     (setq strx (strcat "B " strx))
     (setq strx (strcat "T " strx))
   )
   (setq sl (+ 1 (strlen strx)))
   (setq sl (* wf (* sl th1)))
   (if (< x 0.0)
      ( progn
	(setq ya (+ y th1))
	(setq xa (+ x (* 2.0 th1)))
	(setq pt (list xa ya))
	(setq br 0.0)
      )

     ( progn
       (setq ya (+ y sl))
       ;(setq xa (- x th1))
       (setq xa (- x (* 2.0 th1)))
       (setq pt (list xa ya))
       (setq br 180.0)
     )
  )

  (command "TEXT" pt th1 br strx)
)

(defun wrty(x y lr)
   (setq th1 (* 1.8 fac))
   (setq stry (tostr y))

   (if (< y 0.0)
     (setq stry (strcat "S " stry))
     (setq stry (strcat "U " stry))
   )
   (setq sl (+ 1 (strlen stry)))
   (setq sl (* wf (* sl th1)))
   ;(setq sl (* 0.875 (* sl th1)))
   (if (< y 0.0)
     (progn
       (setq ya (+ y th1))
       (if (= lr "r")
	 (setq xa (- x sl))
	 (setq xa (+ x th1))
       )
       (setq pt (list xa ya))
       (setq br 90.0)
     )

     (progn
       (setq ya (- y (* 2.0 th1)))
       (if (= lr "r")
	 (setq xa (- x sl))
	 (setq xa (+ x th1))
       )
       (setq pt (list xa ya))
       (setq br 90.0)
     )
   )

   (command "TEXT" pt th1 br stry)

)
	



(defun tostr(x)
  (setq str (rtos x))
   (setq sl (strlen str))
   (if (< x 0.0)
     (setq str (substr str 2 (- sl 1)))
     (setq str str)
  )
)

(defun wrtx(x y)
   (setq th1 (* 1.8 fac))       
   (setq strx (tostr x))
   (if (< x 0.0)
     (setq strx (strcat "B " strx))
     (setq strx (strcat "T " strx))
   )
   (setq sl (+ 1 (strlen strx)))
   (setq sl (* wf (* sl th1)))
   (if (< x 0.0)
      ( progn
	(setq ya (+ y th1))
	(setq xa (+ x (* 2.0 th1)))
	(setq pt (list xa ya))
	(setq br 0.0)
      )

     ( progn
       (setq ya (+ y sl))
       ;(setq xa (- x th1))
       (setq xa (- x (* 2.0 th1)))
       (setq pt (list xa ya))
       (setq br 180.0)
     )
  )

  (command "TEXT" pt th1 br strx)
)

(defun wrty(x y lr)
   (setq th1 (* 1.8 fac))       
   (setq stry (tostr y))

   (if (< y 0.0)
     (setq stry (strcat "S " stry))
     (setq stry (strcat "U " stry))
   )
   (setq sl (+ 1 (strlen stry)))
   (setq sl (* wf (* sl th1)))
   ;(setq sl (* 0.875 (* sl th1)))
   (if (< y 0.0)
     (progn
       (setq ya (+ y th1))
       (if (= lr "r")
	 (setq xa (- x sl))
	 (setq xa (+ x th1))
       )
       (setq pt (list xa ya))
       (setq br 90.0)
     )

     (progn
       (setq ya (- y (* 2.0 th1)))
       (if (= lr "r")
	 (setq xa (- x sl))
	 (setq xa (+ x th1))
       )
       (setq pt (list xa ya))
       (setq br 90.0)
     )
   )

   (command "TEXT" pt th1 br stry)

)
	


(defun wrtext(x y th brg str)
  (setq pt (list x y))
  (command "Text" pt th brg str)
)

(defun wrhead(sx sy type)
  (setq npl (* 78.5 fac))
  (setq slt1 (* 19.0  fac))
  (setq slt2 (* 5.0  fac))
  (setq srt (* 3.0 fac))
  ;Plot north point symbol
  (command "Layer" "s" "FootNote" "")
  (command "Osnap" "none")
  (setq pt (list sx sy))
  (command "Line"
    pt
    (strcat "@" (rtos npl) "<180.0")
    ""
  )
  (command "Line"
    pt
    (strcat "@" (rtos slt1) "<170.0")
    (strcat "@" (rtos slt2) "<220.0")
    ""
  )
  (setq x (- sx (* 0.5 srt)))
  (setq y (- sy (* 36.0 fac)))
  (setq pt (list x y))
  (command "Line"
    pt
    (strcat "@" (rtos srt) "<90.0")
    ""
  )


  ;Write heading

  (command "Layer" "s" "Title" "")
  ;(setq scale 1000.0)
  (setq ygap (* 15.0 fac))
  (setq x (+ sx (* 10.0 fac)))    ;(- sx (* 114.0 fac)))
  (setq y (- sy (* 5.0 fac)))
  (setq tht (* 5.0 fac))
  (setq brg 90.0)

  (setq data1 (read-line Infile))
  (setq n 1)
  (wrtext x y tht brg data1)
  (setq y (- y ygap))
  (while (/= data1 nil)
    (setq data1 (read-line Infile))
    (setq n (1+ n))
    (if (/= data1 nil)
      (progn
	(if (= n 6)
	  (progn
	  (setq y (+ y (* 3.0 fac)))
	  (setq tht (* 3.0 fac))
	  )
	)
	(if (= n 7)
	  (progn
	  (setq y (+ y (* 3.0 fac)))
	  (setq tht (* 3.5 fac))
	  )
	)

	(if ( > n 5 )
	  (command "Layer" "s" "FootNote" "" )
	)

	(setq sstr (substr data1 1 3))
	(if (/= sstr "NOS")
	  (progn
	    (wrtext x y tht brg data1)
	    (setq y (- y ygap))
	  )
	)
	(if (= n 7)
	  (setpos type)
	)
      )
    )
  )
  (close Infile)


  (if (= type 1)
    (progn
      (setq y (- y (* 120 fac )))
      (setq ygap (* 20.0 fac))
     )
  )
  (if (= type 2)
    (progn
      ; 4/1/2000 (setq y (- y (* 201 fac ))) ; 210
      (setq y (- y (* 189 fac ))) ; 210
      (setq ygap (* 20.0 fac))
     )
  )

  (if (= type 3)
    (progn
      (setq x x1)
      (setq y (- sy (* 2.5 fac )))
      (setq ygap (* 30.0 fac))
    )
  )
  ;(wrtext x y tht brg "Dicarta oleh")
  ;(setq y (- y ygap))
  ;(wrtext x y tht brg "Diperiksa oleh")

  ;(setq y (- y ygap))
  (wrtext x y tht brg "Diluluskan Oleh")

  (if (= type 1)
    (setq y y1)
  )
  (if (= type 2)
    (setq y y1)
  )

  (if (= type 3)
    (progn
      ;20-11-1997
      ;4-1-2000
      ;(setq y (- y ygap))
      ;(setq y (- y (* 43.5 fac))) ;46.0
      (setq y (- y1 (* 120.0 fac))) ;46.0
    )
  )

  (setq tht (* 10.0 fac))
  (command "Layer" "s" "CPNO" "")
  (wrtext x y tht brg (strcat "PA " pa))
)

(defun C:CArea()
  (setq defNo 1)
  (setq defbrg 90.0)
  (if (= scale nil)
    (progn
    (setq scale ( getreal "\n Enter scale of plan, 1: "))
    )
  )
  (if (= made nil)
    (progn
    (command "Layer" "M" "LotNo" "c" "green" "Lotno" "")
    (command "Layer" "M" "Areas" "c" "yellow""areas" "")
    (setq made 1)
    )
  )
  (setq fac (/ scale 1000.0))
  (setq th1 (* 2.5 fac))  ; for lot No.
  (setq th2 (* 1.8 fac))  ; for area.
  (setq th3 (* 1.4 fac))  ; for sq symbol
  (setq wf 0.785)
  (if (= decDn nil)
    (progn
      (setq n (getint "\nArea in sq. metres; how many decimal places? "))
      (setdecDn n)
   )
  )
  (setq pt1 (getPoint "\nPick a point for writing area: "))
  (while (/= pt1 nil)
    (setq LotNo (getstring "\nEnter lot No. or parcel No: "))
    (setq brgdms (getreal
		   (strcat "\nEnter bearing for writing area: <"
		     (rtos defbrg) "> "
		   )
		 )
    )
    (if (= brgdms nil)
      (setq brgdms defbrg)
      (setq defbrg brgdms)
    )
    (setq pt2 (getpoint "\nPick any line of the polygon. "))

    (setq brg (ToDecD brgdms))
    (command "Area" "E" pt2)
    (command "erase" pt2 "")
    (redraw)
    (setq ar (getvar "AREA"))
    ;(setq LotNo (strcat LotNo " "))
    (command "Layer"
	     "Set"
	     "LotNo"
	     ""
    )
    (command "text"
	      pt1
	      th1
	      brg
	      LotNo
    )
    (setq x (car pt1))
    (setq y (cadr pt1))
    (setq sLen (strlen LotNo))
    (setq sLen (* sLen th1))
    (setq sLen (+ sLen 0.9)) ;1.2))
    (setq sLen (* sLen wf))
    (setq brg1 (dtr brg))
    (setq dx (* (sin brg1) sLen))
    (setq dy (* (cos brg1) sLen))
    (setq x (+ x dx))
    (setq y (+ y dy))
    (setq pt1 (list x y))

    (setq s1 (rtos ar))
    ;(setq s1 (strcat " " s1 ))
    (setq s1 (strcat s1 " m" ))
    (command "Layer"
	     "Set"
	     "Areas"
	     ""
    )
    (command "text"
	      pt1
	      th2
	      brg
	      s1
    )

    (setq sLen (strlen s1))
    (setq sLen (* sLen th2))
    (setq sLen (+ sLen 0.3))
    (setq sLen (* sLen wf))
    (setq dx (* (sin brg1) sLen))
    (setq dy (* (cos brg1) sLen))

    (setq x (+ x dx))
    (setq y (+ y dy))

    ;(setq dx (* 0.8 fac))
    ;(setq dy (* 0.8 fac))
    ;(setq dx (* (sin brg1) dx))
    ;(setq dy (* (cos brg1) dy))

    ;(setq x (+ x dx))
    ;(setq y (+ y dy))

    ; push up by 0.8 mm
    (setq gap (* 0.8 fac))
    (setq dx (* (cos brg1) gap))
    (setq dy (* (sin brg1) gap))
    (setq x (- x dx))
    (setq y (+ y dy))
    (setq pt1 (list x y))
    (command "text"
	    pt1
	    th3
	    brg
	    "2"
    )

    (setq pt1 (getPoint "\nPick a point for writing area "))
  )
  (setq decDn nil)
  (setDMS)
)



(defun setdecD0()
  (command "Units" 2 0 1 5 270 "y")
  ; dist in decimal, 0 decimal place, angle in decimal degree
  (command "graphscr")
  (setq decD 1)
)
(defun setdecDn(n)
  (command "Units" 2 n 1 5 270 "y")
  ; dist in decimal, n decimal place, angle in decimal degree
  (command "graphscr")
  (setq decDn 1)
)

(defun dtr(x)
    (* pi (/ x 180.0))
)


; **********************************************************************
;                             CHGTEXT.LSP

;  This program will replace every occurrence of an "old string" with a
;  "new string".  You will be prompted to select the text you wish
;  to change.  Then you will be asked to enter the "old string" and
;  the "new string".  After the text has been changed, the total number
;  of changed lines is displayed.
; **********************************************************************

(defun chgterr (s)
   (if (/= s "Function cancelled")   ; If an error (such as CTRL-C) occurs
      (princ (strcat "\nError: " s)) ; while this command is active...
   )
   (setq p nil)                      ; Free selection set
   (setq *error* olderr)             ; Restore old *error* handler
   (princ)
)

;(defun C:CHGTEXT (/ p l n e os as ns st s nsl osl sl si chf chm olderr)
(defun C:CT (/ p l n e os as ns st s nsl osl sl si chf chm olderr)
   (setq olderr  *error*             ; Initialize variables
         *error* chgterr
         chm     0)
   (setq p (ssget))                  ; Select objects
   (if p (progn                      ; If any objects selected
      (while (= 0 (setq osl (strlen (setq os (getstring t "\nOld string: ")))))
            (princ "Null input invalid")
      )
      (setq nsl (strlen (setq ns (getstring t "\nNew string: "))))
      (setq l 0 n (sslength p))
      (while (< l n)                 ; For each selected object...
         (if (= "TEXT"               ; Look for TEXT entity type (group 0)
                (cdr (assoc 0 (setq e (entget (ssname p l))))))
            (progn
               (setq chf nil si 1)
               (setq s (cdr (setq as (assoc 1 e))))
               (while (= osl (setq sl (strlen
                             (setq st (substr s si osl)))))
                  (if (= st os)
                      (progn
                        (setq s (strcat (substr s 1 (1- si)) ns
                                        (substr s (+ si osl))))
                        (setq chf t) ; Found old string
                        (setq si (+ si nsl))
                      )
                      (setq si (1+ si))
                  )
               )
               (if chf (progn        ; Substitute new string for old
                  (setq e (subst (cons 1 s) as e))
                  (entmod e)         ; Modify the TEXT entity
                  (setq chm (1+ chm))
               ))
            )
         )
         (setq l (1+ l))
      )
   ))
   (princ "Changed ")                ; Print total lines changed
   (princ chm)
   (princ " text lines.")
   (terpri)
   (setq *error* olderr)             ; Restore old *error* handler
   (princ)
)


( defun getmpt(pt1 pt2)
  (setq x1 (car pt1))
  (setq y1 (cadr pt1))
  (setq x2 (car pt2))
  (setq y2 (cadr pt2))
  (setq xmpt(* (+ x1 x2) 0.5))
  (setq ympt(* (+ y1 y2) 0.5))
  (setq mpt (list xmpt ympt))
  ;(polar pt1
  ;  (angle pt1 pt2)
  '  (/(distance pt1 pt2) 2)
  ;)
)

( defun mpt(pt1 pt2)
  (polar pt1
    (angle pt1 pt2)
    (/(distance pt1 pt2) 2)
  )
)
( defun getdms (pt1 pt2)
   
   (setq space " ")

   (setq d3 (angle pt1 pt2))
   (setq d1 (rtd d3))
   ;(setq d1 (* (/ d3 pi) 180.0))
   (setq d1 (- 450.0 d1))

   (if (>= d1 360.0)  (setq d1 (- d1 360.0)))

   (setq d (fix d1))
   (setq m1  (* (- d1 d) 60.0))
   (setq m (fix m1))
   (setq s1  (* (- m1 m) 60.0))
   (setq s (fix s1))
   (setq s (+ s 5))
   (setq s (* (/ s 10) 10))
   (cond (
           ( >= s 60)
           (setq s (- s 60))
           (setq m (+ m 1))
          )
    )
    (cond (
           ( >= m 60)
           (setq m (- m 60))
           (setq d (+ d 1))
          )
    )
    (cond (
           ( >= d 360)
           (setq d (- d 360))
          )
    )

    (setq ds (itoa d))
    (setq ms (itoa m))
    (setq l1 (strlen ms))
    (if (= (strlen ms) 1) (setq ms (strcat "0" ms)))

    (setq ss (itoa s))
    (setq l2 (strlen ss))
    (if (= (strlen ss) 1) (setq ss (strcat "0" ss)))

    (setq dms (strcat ds "%%d" ms (chr 39) ss (chr 34)))
    ;(strcat ds chr(248)  ms chr(39) ss chr(34))

 )
( defun getdist (pt1 pt2)

   (setq dist (distance pt1 pt2))
   (rtos dist)
   ;(rtos 5.123)
)


(defun c:dpar()
  (setq dist (getreal "\n Enter offset distance. "))
  (setq pt1 (getpoint "\n Define the first point. "))
  (setq pt2 (getpoint "\n Define the next point. "))
  (while (not (equal pt2 nil))
    (setq ang (angle pt1 pt2))
    (setq ang (- ang (* pi 0.5)))
    (setq pt1a (polar pt1 ang dist))
    (setq pt2a (polar pt2 ang dist))
    (command "line" pt1a pt2a "")
    (setq pt1 pt2)
    (setq pt2 (getpoint "\n Define the next point. "))
   )
)

(defun rtd (a) (* 180.0 (/ a pi)))
(defun dtr (a) (* pi (/ a 180.0)))
(defun brgd (pt1 pt2)
   (setq d3 (angle pt1 pt2))
   (setq d1 (rtd d3))
   (setq d1 (- 450.0 d1))

   (if (>= d1 360.0)  (setq d1 (- d1 360.0)))
   (+ d1 0)
)

(defun updn (pt1 pt2 d1 offset ht leng n)
    (setq ra (dtr d1))
    (setq oldra ra)
    (setq brg1 (- ra ( * pi 0.5))) ;brg-90

    (if ( >= ra pi) (setq ra (- ra pi)))
    (getmpt pt1 pt2) ; return mpt
    ;(setq npt (mpt pt1 pt2))
    (setq npt mpt)

    ; Annotate brg above line

    (setq dx (* offset (sin brg1)))
    (setq dy (* offset (cos brg1)))
    (setq xht (* 1.15 ( * ht (sin brg1))))
    (setq yht (* 1.15 ( * ht (cos brg1))))

    ;(setq xht (* 1.1 ( * ht (sin brg1))))
    ;(setq yht (* 1.1 ( * ht (cos brg1))))
    ;(setq xht (* 1.05 ( * ht (sin brg1))))
    ;(setq yht (* 1.05 ( * ht (cos brg1))))

    ;(setq x ( + (car npt) dx))
    ;(setq y ( + (cadr npt) dy))

    (if (= n 1) (setq x ( + (car npt) dx)) (setq x ( - (car npt) dx)))
    (if (= n 1) (setq y ( + (cadr npt) dy)) (setq y ( - (cadr npt) dy)))

    (cond
      ( ( = n 1)
      (if ( >= oldra pi) (setq x ( + x xht)))
      (if ( >= oldra pi) (setq y ( + y yht)))
      )
    )
    (cond
      ( ( = n 2)
      (if ( < oldra pi) (setq x ( - x  xht )))
      (if ( < oldra pi) (setq y ( - y  yht )))

      ;(if ( >= oldra pi) (setq x ( + x xht)))
      ;(if ( >= oldra pi) (setq y ( + y yht)))
      )
    )

    ;(if (< ra pi) (setq ra (+ ra pi)))
    (setq dx (* leng (sin ra)))
    (setq dy (* leng (cos ra)))

    (setq x (- x dx))
    (setq y (- y dy))


    (list x y)
)


(defun c:wbdP()
  (prompt "\nWriting bearing and/or distance for lines")
  (setq offset1 0.6)
  (setq wf 0.785)
  (if (= done nil) (setDMS))
  (cond
    ( (or (= scale 0) (= scale nil))
       (setq scale (getreal "\Enter scale:  1:  <1000> " ))
       (if (= scale nil) (setq scale 1000.0))
    )
  )
  (if (= ht nil)
      (progn
        (setq aht (getreal "\Enter text ht for brg and dist: <1.6mm> "))
        (if (= aht nil) (setq aht 1.6))
      )
  )
  (setq sf (/ scale 1000.0))
  (setq ht (* aht sf))
  (setq offset (* offset1 sf))

  (setq choice 0)
  (if (or (<= choice 0) (> choice 4))
    (setq choice
    (getint "\n 1=brg only  2=dist only  3=brg above, dist below  4=brg & dist same line ")
    )
  )

  (setq pt1 (getpoint "\n define first point "))
  (setq pt2 (getpoint "\n define next point "))

  (while (not (equal pt2 nil))
    (setq dms (getdms pt1 pt2))
    (setq noc1 (- (strlen dms) 4.1))
    ; %%d ' and " (5 characters) taken as 0.9 character
    (setq leng1 ( * noc1 ht ))
    (setq leng1 ( * (* leng1 wf) 0.5))
    (setq d1 (brgd pt1 pt2))

    (setq diss (getdist pt1 pt2))
    (setq noc2 (- (strlen diss) 0.8))
    ; . taken as 0.2 character
    (setq leng2 (* noc2 ht ))
    (setq leng2 (* (* leng2 wf) 0.5))

    (cond
      ( (or (= choice 1) (= choice 3))
        (setq n 1)
        (setq pt (updn pt1 pt2 d1 offset ht leng1 n))
        (setq d2 d1)
        (if (>= d1 180.0) (setq d1 (- d1 180.0)))
        (command "text" pt ht d1 dms)
        (setq d1 d2)
        )
      )

    (cond
       ( (or (= choice 2) (= choice 3))
         (setq n 2)
         (setq pt (updn pt1 pt2 d1 offset ht leng2 n))
         (if (>= d1 180.0) (setq d1 (- d1 180.0)))
         (command "text" pt ht d1 diss)
       )
    )

    (cond
      ( (= choice 4)
        (setq bandd (strcat dms "  " diss))
        (setq leng3 (+ leng1 leng2))
        (setq n 1)
        (setq pt (updn pt1 pt2 d1 offset ht leng3 n))
        (if (>= d1 180.0) (setq d1 (- d1 180.0)))
        (command "text" pt ht d1 bandd)
      )
    )
    ;(command "text" pt ht d1 diss)
    (setq pt1 pt2)
    (setq pt2 (getpoint "\n define next point "))
  )
)

(defun c:wbdOld()
  (prompt "\nWriting bearing and/or distance for lines")
  (setq offset1 0.6)
  (setq wf 0.785) ;0.857143)
  (if (= done nil) (setDMS))
  (cond
    ( (or (= scale 0) (= scale nil))
       (setq scale (getreal "\Enter scale:  1:  <1000> " ))
       (if (= scale nil) (setq scale 1000.0))

       (setq ht (getreal "\Enter text ht for brg and dist: <1.6mm> "))
       (if (= ht nil) (setq ht 1.6))
       (setq sf (/ scale 1000.0))
       (setq ht (* ht sf))
       (setq offset (* offset1 sf))
    )
  )

  (setq choice 0)
  (if (or (<= choice 0) (> choice 4))
    ;(princ  "\n 1=Brg only  2=Dist only  3=Brg above, dist below")
    (setq choice
    (getint "\n 1=brg only  2=dist only  3=brg above, dist below  4=brg & dist same line ")
    )
  )
  (setq counter 0)
  (setq ENTITIES (ssget))
  (setq NofItems (sslength ENTITIES))

  (repeat NofItems

    (setq EName (ssname ENTITIES counter))
    (setq EList (entget Ename))
    (setq Etype (cdr (assoc 0 EList)))
    (if (equal Etype "LINE")
      (progn
        (setq pt1 (cdr (assoc 10 Elist)))
        (setq pt2 (cdr (assoc 11 Elist)))
        (setq dms (getdms pt1 pt2))
        (setq noc1 (- (strlen dms) 4.1))
        ; %%d ' and " (5 characters) taken as 0.9 character
        (setq leng1 ( * noc1 ht ))
        (setq leng1 ( * (* leng1 wf) 0.5))
        (setq d1 (brgd pt1 pt2))

        (setq diss (getdist pt1 pt2))
        (setq noc2 (- (strlen diss) 0.8))
        ; . taken as 0.2 character
        (setq leng2 (* noc2 ht ))
        (setq leng2 (* (* leng2 wf) 0.5))

        (cond
          ( (or (= choice 1) (= choice 3))
            (setq n 1)
            (setq pt (updn pt1 pt2 d1 offset ht leng1 n))
            (setq d2 d1)
            (if (>= d1 180.0) (setq d1 (- d1 180.0)))
            (command "text" pt ht d1 dms)
            (setq d1 d2)
          )
        )

        (cond
          ( (or (= choice 2) (= choice 3))
            (setq n 2)
            (setq pt (updn pt1 pt2 d1 offset ht leng2 n))
            (if (>= d1 180.0) (setq d1 (- d1 180.0)))
            (command "text" pt ht d1 diss)
          )
        )

        (cond
          ( (= choice 4)
            (setq bandd (strcat dms "  " diss))
            (setq leng3 (+ leng1 leng2))
            (setq n 1)
            (setq pt (updn pt1 pt2 d1 offset ht leng3 n))
            (if (>= d1 180.0) (setq d1 (- d1 180.0)))
            (command "text" pt ht d1 bandd)
          )
        )
      )
    )
    (setq counter (1+ counter))
  )
)


(defun c:mpar()
  ;(textscr)
  ;(princ)
  (setq bl " ")
  (setq dist (getreal "\n Enter distance between paralles. "))
  (setq repeat (getint "\n How many paralles? "))
  (setq pt1 (getpoint "\n Define the first point. "))
  (setq pt2 (getpoint "\n Define the next point. "))
  (setq n 1)
  (while (<= n repeat)
    (setq ang (angle pt1 pt2))
    (setq ang1 (- ang (* pi 0.5)))
    (setq pt1a (polar pt1 ang1 dist))
    (setq pt2a (polar pt2 ang1 dist))
    (command "line" pt1a pt2a "")
    (setq pt1 pt1a)
    (setq pt2 pt2a)
    (setq n (+ n 1))
   )
)

;                           REF.LSP

; This is a useful routine for obtaining a relative point.
; It can be used whenever an AutoCAD command requests a point.
; Just enter "(ref)" in response to the "...point:" prompt, and
; enter the desired base (reference) point and the relative/polar
; offset from that point. For example:

;    Command: LINE
;    From point: (ref)
;    Reference point: (...pick a point...)
;    Enter relative/polar coordinate (with @): @x,y or @dist<angle
;    To point:

(defun c:ploffset ()
  
  ;(command "Units" 2 3 1 4 90 Y)
  ;(graphscr)
  ;(setq pi 3.14159)
  (setq pt1 (list 1,1))
  ;(setq brg 0.0)
  (setq pt1 (getpoint "\nReference point: "))
  (while (/= pt1 nil)
    (setq brg (getreal "\nEnter bearing: "))
    (while (>= brg 0.0)
      (setq dis (getreal "\nEnter distance: "))
      (setq brg (- 90.0 brg)) ;9/1/92 closewise from East 
      (setq brg1 (/ brg 180.0))
      (setq brg2 (* brg1 pi))
      (setq pt3 (polar pt1 brg2 dis))
      (command "point" pt3)
      (setq brg (getreal "\nEnter bearing: "))
    )
    (setq pt1 (getpoint "\nReference point: "))
  )
)

(defun c:dpar()
  (setq dist (getreal "\n Enter offset diatance. "))
  (setq pt1 (getpoint "\n Define the first point. "))
  (setq pt2 (getpoint "\n Define the next point. "))
  (while (not (equal pt2 nil))
    (setq ang (angle pt1 pt2))
    (setq ang (- ang (* pi 0.5)))
    (setq pt1a (polar pt1 ang dist))
    (setq pt2a (polar pt2 ang dist))
    (command "line" pt1a pt2a "")
    (setq pt1 pt2)
    (setq pt2 (getpoint "\n Define the next point. "))
   )
)

(defun c:pcc() ; Plot corner cuts
  (if (= done nil) (setDMS))
  (setq disdef 6.096)
  (setq svar (rtos disdef))
  (setq ptr (getpoint "\nReference point: "))
  (while (/= ptr nil)
    (setq prom (strcat "\Enter corner cut distance <" svar "> " ))
    (prompt prom) ; "\nEnter corner cut distance "  "<" svar "> ")
    (setq dis (getreal))
    (if (= dis nil) (setq dis disdef))
    (setq disdef dis)
    (setq svar (rtos disdef))
    (setq Sbg (getstring "\nEnter bearing of 1st line: "))
    ;(setq brg (getreal "\nEnter bearing1: "))

    (setq brgdms (atof Sbg))
    (setq brg (ToDecD brgdms))
    (setq brg2 (+ 90.0 brg))   ; Note: Enter brg clockwise direction
    (setq brg1 (- 90.0 brg)) ;9/1/92 closewise from East
    (setq brg2 (- 90.0 brg2))
    ;(if (>= brg2 360.0)  (setq brg2 (- brg2 360.0)))
    (setq brg1 (dtr brg1))
    (setq brg2 (dtr brg2))

    '(setq brg1 (/ brg 180.0))
    '(setq brg1 (* brg1 pi))
    (setq pt1 (polar ptr brg1 dis))
    (setq pt2 (polar ptr brg2 dis))
    (command "line" pt2 pt1 "")
    (setq ptr (getpoint "\nReference point: "))
  )
)

;  **** TextHt.LSP ***  Global text height change * By S.E. Tee on 7 April 1998
;  - modified from TXROT.LSP by T.L. YAP - 14 Aug.1991
;

(defun update()
     (setq txHt (cdr (assoc 40 alist) ))
     (setq txHt (* newFac txHt))
     (setq alist
         (subst (cons 40 txHt)
              (assoc 40 alist)
              alist
         )
     )
     (entmod alist)
     (setq test (1+ test))
     (setq ename (ssname txtset test))
     (if (/= ename nil)
         (setq alist (entget ename))
     )
)

(defun next()
     (setq test (1+ test))
     (setq ename (ssname txtset test))
     (if (/= ename nil)
         (setq alist (entget ename))
     )
)

(defun C:TextHt ()
     (setq oldech (getvar "CMDECHO"))
     (setvar "CMDECHO" 0)
     (setq newfac (getreal "\nEnter multiplying factor for text height: "))
     (setq txtset (ssget))
     (setq total (sslength txtset))
     (setq test 0)
     (setq ename (ssname txtset 0))
     (if (/= ename nil)
         (setq alist (entget ename))
     )
     (while (< test total)
            (if (= "TEXT" (cdr(assoc 0 alist)))
                (update)
                (next)
            )
     )
     (setvar "CMDECHO" oldech)
)

;===============================================================================
;     THEIGHT - Text Height Changer
;===============================================================================

(defun C:THEIGHT ()

 '    (prompt "\nTHEIGHT - Text height changer")

     (setq ENTITIES (ssget))
     (setq NO_OF_ENTITIES (sslength ENTITIES))

     ;(setq VALUE (getdist "\nEnter new text height : "))
'     (setq VALUE (getreal "\nEnter new text height : "))
     (setq SSPOSITION 0)

     (repeat NO_OF_ENTITIES

         (setq ENTITY_NAME (ssname ENTITIES SSPOSITION))
         (setq OLD_ENTLIST (entget ENTITY_NAME))
         (setq ENTITY_TYPE (cdr (assoc 0 OLD_ENTLIST)))

         (if (equal ENTITY_TYPE "TEXT")
             (progn
                (setq OLD_HEIGHT  (assoc 40 OLD_ENTLIST))
                (setq NEW_HEIGHT  (cons  40 VALUE))
                (setq NEW_ENTLIST (subst NEW_HEIGHT OLD_HEIGHT OLD_ENTLIST))
                (entmod NEW_ENTLIST)
             )
         )

         (setq SSPOSITION (1+ SSPOSITION))
     )

     (prompt "\nProgram Complete.")

     (princ)

)

(defun c:wbd()
  (prompt "\nWriting bearing and/or distance for lines")
  (setq offset1 0.6)
  (setq wf 0.785)
  (if (= done nil) (setDMS))
  (cond
    ( (or (= scale 0) (= scale nil))
       (setq scale (getreal "\Enter scale:  1:  <1000> " ))
       (if (= scale nil) (setq scale 1000.0))
       (setq aht (getreal "\Enter text ht for brg and dist: <1.6mm> "))
       (if (= aht nil) (setq aht 1.6))
    )
  )

  (setq sf (/ scale 1000.0))
  (setq ht (* aht sf))
  (setq offset (* offset1 sf))
  (setq choice 0)
  (if (or (<= choice 0) (> choice 4))
    ;(princ  "\n 1=Brg only  2=Dist only  3=Brg above, dist below")
    (setq choice
    (getint "\n 1=brg only  2=dist only  3=brg above, dist below  4=brg & dist same line ")
    )
  )
  (setq counter 0)
  (setq ENTITIES (ssget))
  (setq NofItems (sslength ENTITIES))

  (repeat NofItems

    (setq EName (ssname ENTITIES counter))
    (setq EList (entget Ename))
    (setq Etype (cdr (assoc 0 EList)))
    (if (equal Etype "LINE")
      (progn
        (setq pt1 (cdr (assoc 10 Elist)))
        (setq pt2 (cdr (assoc 11 Elist)))
        (setq dms (getdms pt1 pt2))
        (setq noc1 (- (strlen dms) 4.1))
        ; %%d ' and " (5 characters) taken as 0.9 character
        (setq leng1 ( * noc1 ht ))
        (setq leng1 ( * (* leng1 wf) 0.5))
        (setq d1 (brgd pt1 pt2))

        (setq diss (getdist pt1 pt2))
        (setq noc2 (- (strlen diss) 0.8))
        ; . taken as 0.2 character
        (setq leng2 (* noc2 ht ))
        (setq leng2 (* (* leng2 wf) 0.5))

        (cond
          ( (or (= choice 1) (= choice 3))
            (setq n 1)
            (setq pt (updn pt1 pt2 d1 offset ht leng1 n))
            (setq d2 d1)
            (if (>= d1 180.0) (setq d1 (- d1 180.0)))
            (command "text" pt ht d1 dms)
            (setq d1 d2)
          )
        )

        (cond
          ( (or (= choice 2) (= choice 3))
            (setq n 2)
            (setq pt (updn pt1 pt2 d1 offset ht leng2 n))
            (if (>= d1 180.0) (setq d1 (- d1 180.0)))
            (command "text" pt ht d1 diss)
          )
        )

        (cond
          ( (= choice 4)
            (setq bandd (strcat dms "  " diss))
            (setq leng3 (+ leng1 leng2))
            (setq n 1)
            (setq pt (updn pt1 pt2 d1 offset ht leng3 n))
            (if (>= d1 180.0) (setq d1 (- d1 180.0)))
            (command "text" pt ht d1 bandd)
          )
        )
      )
    )
    (setq counter (1+ counter))
  )
)

(defun c:sbrg()
  (prompt "\nWriting bearing and/or distance for lines")
  (setq offset1 0.6)
  (setq wf 0.785)
  ;(if (= done nil) (setDMS))

  ;(cond
  ;  ( (or (= scale 0) (= scale nil))
  ;     (setq scale (getreal "\Enter scale:  1:  <1000> " ))
  ;     (if (= scale nil) (setq scale 1000.0))

       ;(setq ht (getreal "\Enter text ht for brg and dist: <1.8mm> "))
       ;(if (= ht nil) (setq ht 1.8))
   ;    (setq sf (/ scale 1000.0))
       ;(setq tht (* ht sf))
  ;     (setq offset (* offset1 sf))
  ;  )
; )

  (setq counter 0)
  (setq found 0)
  (setq toCheck 0)
  (setq reWrite 0)
  (setq ENTITIES (ssget))
  (setq NofItems (sslength ENTITIES))

  (repeat NofItems

    (setq EName (ssname ENTITIES counter))
    (setq EList (entget Ename))
    (setq Etype (cdr (assoc 0 EList)))

    (if (equal Etype "TEXT")
      ;check for brg text
      (progn
        (setq text1 (assoc 1 Elist))
        (setq textStr (cdr text1))
        (setq size (strlen textStr))
        ;(setq i 1)
        ;(repeat size
        (if (equal (substr textStr size 1) (chr 34)) ; "
          ;(progn
            (setq found 1)
          ;)
        )
        ;  (setq i (1+ i))
        ;)

        (if (= found 1)
          (progn
            (setq toCheck (1+ toCheck))
            (if (= toCheck 1)
              (progn
                (setq textStr1 textStr)
                (setq spt (cdr (assoc 10 Elist)))
                (setq apt1 (cdr (assoc 11 Elist))) ; alignment pt

                (setq rangle (cdr (assoc 50 Elist))) ; rotation angle in rad
                (setq tht (cdr (assoc 40 Elist))) ; text ht
              )
            )
            (if (> toCheck 1)
              (progn
                (if (equal textStr textStr1)
                  (progn
                    (setq ept (cdr (assoc 10 Elist)))
                    (setq apt2 (cdr (assoc 11 Elist))) ; alignment pt
                    (command ".ERASE" ept "")
                    (setq reWrite 1)
                  )
                )
              )
            )
          )
        )
      )
    )
    (setq counter (1+ counter))
  )
  (if (= reWrite 1)
    (progn
      (setq reWrite 0)
      (FindDMS textStr)  ;return dstr mstr sstr brgDecD brgDecD1
      ;(setq rangle (/ (* rangle 180) PI))
      (setq rangle brgDecD)
      (command ".ERASE" spt "")
      (if (/= apt1 nil)
        (setq spt apt1)
      )
      (if (/= apt2 nil)
        (setq ept apt2)
      )

      (setq x1 (car spt))
      (setq y1 (cadr spt))
      (setq x2 (car ept))
      (setq y2 (cadr ept))
      (setq xm (* (+ x1 x2) 0.5))
      (setq ym (* (+ y1 y2) 0.5))
      (setq mpt (list xm ym))

      (command ".TEXT" "J" "C" spt tht rangle dstr)
      (command ".TEXT" "J" "C" mpt tht rangle mstr)
      (command ".TEXT" "J" "C" ept tht rangle sstr)
    )
  )
  (princ)
)

(defun FindDMS(brgstr) ;return dstr mstr sstr brgDecD, brgDecD1
  (setq i1 1)
  (repeat (strlen brgstr)
    (if (equal (substr brgstr i1 1) "d")
      (setq p1 i1)
    )
    (if (equal (substr brgstr i1 1) "'")
      (setq p2 i1)
    )
    (if (equal (substr brgstr i1 1) (chr 34))
      (setq p3 i1)
    )
    (setq i1 (1+ i1))
  )
  (setq nofCh (- p1 3))
  (setq dstr (substr brgstr 1 nofCh))
  (setq p2 (- p2 2))
  (setq mstr (substr brgstr p2 2))
  (setq p3 (- p3 2))
  (setq sstr (substr brgstr p3 2))
  (setq bd (atoi dstr))
  (setq bm (atoi mstr))
  (setq bs (atoi sstr))
  (setq brgDecD (+ bd ( / bm 60.0)))
  (setq brgDecD (+ brgDecD ( / bs 3600.0)))
  (setq brgDecD1 brgDecD)
  (if (>= brgDecD 180.0)
    (setq brgDecD (- brgDecD 180.0))
  )
  (setq dstr(strcat dstr "%%d"))
  (setq mstr(strcat mstr "'"))
  (setq sstr(strcat sstr (chr 34)))
)

(defun c:90d()
  (setq wf 0.785)
  (prompt "\nRotate lot number & area to 90 deg")

  (if (= scale nil)
    (progn
      (setq scale (getreal "\n Enter scale:  1:  <1000> " ))
      (if (= scale nil) (setq scale 1000.0))
    )
  )
  (setq sf (/ scale 1000.0))

  (setq dx 0 ) ; (* 1.0 sf))
  (setq dy (* 5.0 sf))

  (setq counter 0)
  (setq found 0)
  (setq toCheck 0)
  (setq reWrite 0)
  (setq ENTITIES (ssget))
  (setq NofItems (sslength ENTITIES))

  (repeat NofItems

    (setq EName (ssname ENTITIES counter))
    (setq EList (entget Ename))
    (setq Etype (cdr (assoc 0 EList)))
    (setq layer (cdr (assoc 8 Elist)))

    (if (and
           (equal Etype "TEXT")
           (equal layer "LOTNO")
        )
      (progn
        (setq pt1 (cdr (assoc 10 Elist)))
        (setq rangR (cdr (assoc 50 Elist)))
        (setq LotStr (cdr (assoc 1 Elist)))
        (setq Entity1 Ename)
      )
    )

    (if (and
          (equal Etype "TEXT")
          (equal layer "AREAS")
        )
      (progn
        (setq textStr (cdr (assoc 1 Elist)))
        (if
           (/= textStr "2")
           (progn
             (setq pt2 (cdr (assoc 10 Elist)))
             (setq Entity2 Ename)
           )
           (setq Entity3 Ename)
        )
      )
    )
    (setq counter (1+ counter))
  )


  (setq Nofch (strlen lotstr))
  (setq textLen (* Nofch 3.2))
  (setq textLen (* textlen sf))
  (setq textLen (* textlen wf))
  (setq dx1 (* textLen (cos  rangr)))
  (setq dy1 (* textLen (sin  rangr)))

  (setq pta (list dx1 dy1))
  (setq ptb (list 0.0 0.0))

  (setq xpt (car pt1))
  (setq ypt (cadr pt1))

  (setq xpt (- xpt dx))
  (setq ypt (- ypt dy))
  (setq ptnew (list xpt ypt))

  (setq rang1 (/ (* rangR 180) PI)) ; original rotation angle
                                    ; measured from x axis anti-clockwise
  (command ".ROTATE" entity1 entity2 entity3 "" pt1 rang1)
  (setq EList2 (entget Entity2))
  (setq pt2 (cdr (assoc 10 Elist2)))
  (command ".MOVE" entity2 entity3 "" pt2 ptnew)
  (command ".MOVE" "P" entity1 "" ptb pta)

  (princ)
)

(defun C:TCir()
     (setq pick (entsel "\n Pick the circle to trim"))
     (setq entity (car pick))
     (setq elist (entget entity))
     (setq etype (cdr (assoc 0 elist)))
     (if (equal etype "CIRCLE")
       (progn
         (setq cent (cdr (assoc 10 elist)))
         (setq entity1 (ssget cent))
         (if entity1
             (progn
               (command ".TRIM" entity "" )
               (command cent "" )
             )
         )
       )
     )
     (princ)
 )


(defun C:CArea1()
  (setq defNo 1)
  (setq defbrg 90.0)
  (if (= scale nil)
    (progn
    (setq scale ( getreal "\n Enter scale of plan, 1: "))
    )
  )
  (if (= made nil)
    (progn
    (command "Layer" "M" "LotNo" "c" "green" "Lotno" "")
    (command "Layer" "M" "Areas" "c" "yellow""areas" "")
    (setq made 1)
    )
  )
  (setq fac (/ scale 1000.0))
  (setq th1 (* 2.5 fac))  ; for lot No.
  (setq th2 (* 1.8 fac))  ; for area.
  (setq th3 (* 1.4 fac))  ; for sq symbol
  (setq wf 0.785)
  (if (= decDn nil)
    (progn
      (setq n (getint "\nArea in sq. metres; how many decimal places? "))
      (setdecDn n)
   )
  )
  (setq pt1 (getPoint "\nPick a point for writing area: "))
  (while (/= pt1 nil)
    (setq LotNo (getstring "\nEnter lot No. or parcel No: "))
    (setq brgdms (getreal
		   (strcat "\nEnter bearing for writing area: <"
		     (rtos defbrg) "> "
		   )
		 )
    )
    (if (= brgdms nil)
      (setq brgdms defbrg)
      (setq defbrg brgdms)
    )
    (command "boundary" "a" "o" "r" "" pt1 "" "")

    ;(setq pt2 (getpoint "\nPick any line of the polygon. "))

    (setq brg (ToDecD brgdms))
    ;(command "Area" "E"  pt2)
    ;(command "erase" pt2 "")
    (command "Area" "E"  pt1)
    (command "erase" pt1 "")
    (redraw)
    (setq ar (getvar "AREA"))
    ;(setq LotNo (strcat LotNo " "))
    (command "Layer"
	     "Set"
	     "LotNo"
	     ""
    )
    (command "text"
	      pt1
	      th1
	      brg
	      LotNo
    )
    (setq x (car pt1))
    (setq y (cadr pt1))
    (setq sLen (strlen LotNo))
    (setq sLen (* sLen th1))
    (setq sLen (+ sLen 0.9)) ;1.2))
    (setq sLen (* sLen wf))
    (setq brg1 (dtr brg))
    (setq dx (* (sin brg1) sLen))
    (setq dy (* (cos brg1) sLen))
    (setq x (+ x dx))
    (setq y (+ y dy))
    (setq pt1 (list x y))

    (setq s1 (rtos ar))
    ;(setq s1 (strcat " " s1 ))
    (setq s1 (strcat s1 " m" ))
    (command "Layer"
	     "Set"
	     "Areas"
	     ""
    )
    (command "text"
	      pt1
	      th2
	      brg
	      s1
    )

    (setq sLen (strlen s1))
    (setq sLen (* sLen th2))
    (setq sLen (+ sLen 0.3))
    (setq sLen (* sLen wf))
    (setq dx (* (sin brg1) sLen))
    (setq dy (* (cos brg1) sLen))

    (setq x (+ x dx))
    (setq y (+ y dy))

    ;(setq dx (* 0.8 fac))
    ;(setq dy (* 0.8 fac))
    ;(setq dx (* (sin brg1) dx))
    ;(setq dy (* (cos brg1) dy))

    ;(setq x (+ x dx))
    ;(setq y (+ y dy))

    ; push up by 0.8 mm
    (setq gap (* 0.8 fac))
    (setq dx (* (cos brg1) gap))
    (setq dy (* (sin brg1) gap))
    (setq x (- x dx))
    (setq y (+ y dy))
    (setq pt1 (list x y))
    (command "text"
	    pt1
	    th3
	    brg
	    "2"
    )

    (setq pt1 (getPoint "\nPick a point for writing area "))
  )
  (setq decDn nil)
  (setDMS)
)
