(DEFUN C:GPAB ()
;SET LAYER
(COMMAND "SETVAR" "CMDECHO" 0)
(SETQ NY (GETVAR "CLAYER"))
;(IF (= (TYPE F1) 'FILE ) "YES"  (STOP))
;(IF (= (TYPE F2) 'FILE ) "YES" (STOP))
(setq GPSET (findfile "c:/acad/ACAD/SUPPORT/GP.SET"))
(IF (= GPSET NIL)
    (PROGN
       (PROMPT "\nPLEASE SETTING LAYER GIUDE PIN :" )
       (SETQ FC (OPEN "c:/acad/ACAD/SUPPORT/GP.SET" "w"))
       (setq GPCNT (GETSTRING T"\nSETTING GUIDE PIN  LAYER OF CONTNIUE LINE ? <0>:"))
       (IF (= GPCNT "")
              (WRITE-LINE "0" FC)
              (WRITE-LINE GPCNT FC)
       )
       (setq GPCEN (GETSTRING T"\nSETTING GUIDE PIN LAYER OF CENTER LINE ? <CEN>:"))
       (IF (= GPCEN "")
              (WRITE-LINE "CEN" FC)
              (WRITE-LINE GPCEN FC)
       )
       (setq GPHID (GETSTRING T"\nSETTING GUIDE PIN LAYER OF HIDDEN LINE ? <HID>:"))
       (IF (= GPHID "")
              (WRITE-LINE "HID" FC)
              (WRITE-LINE GPHID FC)
       )
       (setq GPDIM (GETSTRING T"\nSETTING GUIDE PIN WORD IS LP OR GP ? <GP>:"))
       (IF (= GPDIM "")
              (WRITE-LINE "GP" FC)
              (WRITE-LINE GPDIM FC)
       )
       (setq GPTXT (GETSTRING T"\nSETTING GUIDE PIN LAYER OF TEXT ? <TEXT>:"))
       (IF (= GPTXT "")
              (WRITE-LINE "TEXT" FC)
              (WRITE-LINE GPTXT FC)
       )
       (CLOSE FC)
    )
)

(IF (/= GPSET NIL)
    (PROGN
       (SETQ FC (OPEN "c:/acad/ACAD/SUPPORT/GP.SET" "r"))
       (SETQ GPCNT (READ-LINE FC))
       (SETQ GPCEN (READ-LINE FC))
       (SETQ GPHID (READ-LINE FC))
       (SETQ GPDIM (READ-LINE FC))
       (SETQ GPTXT (READ-LINE FC))
       (IF (OR (= GPCNT "") (= GPCEN "") (= GPHID "") (= GPDIM "") (= GPTXT "")
               (= GPCNT NIL) (= GPCEN NIL) (= GPHID NIL) (= GPDIM NIL) (= GPTXT NIL))
           (CLOSE FC)
       )
       (IF (OR (= GPCNT "") (= GPCEN "") (= GPHID "") (= GPDIM "") (= GPTXT "")
               (= GPCNT NIL) (= GPCEN NIL) (= GPHID NIL) (= GPDIM NIL) (= GPTXT NIL))
           (PROGN
              (PROMPT "\nPLEASE SETTING LAYER GIUDE PIN :" )
              (SETQ FC (OPEN "c:/acad/ACAD/SUPPORT/GP.SET" "w"))
              (setq GPCNT (GETSTRING T"\nSETTING GUIDE PIN  LAYER OF CONTNIUE LINE ? <0>:"))
              (IF (= GPCNT "")
                  (WRITE-LINE "0" FC)
                  (WRITE-LINE GPCNT FC)
              )
              (setq GPCEN (GETSTRING T"\nSETTING GUIDE PIN LAYER OF CENTER LINE ? <CEN>:"))
              (IF (= GPCEN "")
                  (WRITE-LINE "CEN" FC)
                  (WRITE-LINE GPCEN FC)
              )
              (setq GPHID (GETSTRING T"\nSETTING GUIDE PIN LAYER OF HIDDEN LINE ? <HID>:"))
              (IF (= GPHID "")
                  (WRITE-LINE "HID" FC)
                  (WRITE-LINE GPHID FC)
              )
              (setq GPDIM (GETSTRING T"\nSETTING GUIDE PIN WORD IS LP OR GP ? <GP>:"))
              (IF (= GPDIM "")
                  (WRITE-LINE "GP" FC)
                  (WRITE-LINE GPDIM FC)
              )
              (setq GPTXT (GETSTRING T"\nSETTING GUIDE PIN LAYER OF TEXT ? <TEXT>:"))
              (IF (= GPTXT "")
                  (WRITE-LINE "TEXT" FC)
                  (WRITE-LINE GPTXT FC)
              )
           (CLOSE FC)
           )
       )
       (SETQ FC (OPEN "c:/acad/ACAD/SUPPORT/GP.SET" "r"))
       (SETQ GPCNT (READ-LINE FC))
       (SETQ GPCEN (READ-LINE FC))
       (SETQ GPHID (READ-LINE FC))
       (SETQ GPDIM (READ-LINE FC))
       (SETQ GPTXT (READ-LINE FC))
       (CLOSE FC)
       (PROMPT "\nG.P CONTINUE OF LAYER IS:" )(PROMPT GPCNT)(TERPRI)
       (PROMPT "\nG.P CENTER OF LAYER IS:" ) (PROMPT GPCEN)(TERPRI)
       (PROMPT "\nG.P HIDDEN OF LAYER IS:" ) (PROMPT GPHID)(TERPRI)
       (PROMPT "\nG.P DIMENSION OF LAYER IS:" ) (PROMPT GPDIM)(TERPRI)
       (PROMPT "\nG.P TEXT   OF LAYER IS:" ) (PROMPT GPTXT)(TERPRI)
    )
)

(MENUCMD "S=GP")
(SETQ D (GETREAL"\nSelect dim:"))
(IF  (= (SETQ ANS1 (GETSTRING "\nDOU YOU WANT TO CUT PART LINE (P2) :<Y>")) "")
     (SETQ ANS1 "Y"))
(SETQ ANS1 (STRCASE ANS1))
(IF (AND (>= D 16) (< D 20))
    (PROGN
     (SETQ BD (+ D 4))
     (SETQ H  6)
     (SETQ M  8)
     (SETQ R  2.0)
     (SETQ FR  1.83)
     (SETQ BUD (+ D 14))
     (SETQ BUD1 (+ D 9))
     (SETQ BUH  6)
     (SETQ BUR  3)
     (SETQ W 3  )
     (SETQ P 16)
   )
)
(IF (AND (>= D 20) (< D 25))
    (PROGN (SETQ BD (+ D 5))
           (SETQ H  6)
           (SETQ M  10)
           (SETQ R  2.5)
           (SETQ FR  2.29)
           (SETQ BUD (+ D 15))
           (SETQ BUD1 (+ D 10))
           (SETQ BUH  8)
           (SETQ BUR  3)
           (SETQ W 3  )
           (SETQ P 20)
)   )
(IF (AND (>= D 25) (< D 30))
    (PROGN (SETQ BD (+ D 5))
           (SETQ H  8)
           (SETQ M  12)
           (SETQ R  2.5)
           (SETQ FR  2.75)
           (SETQ BUD (+ D 15))
           (SETQ BUD1 (+ D 10))
           (SETQ BUH  8)
           (SETQ BUR  3)
           (SETQ W 3  )
           (SETQ P 25)
)   )
(IF (AND (>= D 30) (< D 35))
    (PROGN (SETQ BD (+ D 5))
           (SETQ H  8)
           (SETQ M  15)
           (SETQ R  3)
           (SETQ FR  2.75)
           (SETQ BUD (+ D 17))
           (SETQ BUD1 (+ D 12))
           (SETQ BUH 10)
           (SETQ BUR  3)
           (SETQ W 3  )
           (SETQ P 30)
)   )
(IF (AND (>= D 35) (< D 40))
    (PROGN (SETQ BD (+ D 5))
           (SETQ H  8)
           (SETQ M  15)
           (SETQ R  3)
           (SETQ FR  2.75)
           (SETQ BUD (+ D 19))
           (SETQ BUD1 (+ D 13))
           (SETQ BUH 10)
           (SETQ BUR  4)
           (SETQ W 4  )
          (SETQ P 30)
)   )
(IF (AND (>= D 40) (< D 50))
    (PROGN (SETQ BD (+ D 5))
           (SETQ H  10)
           (SETQ M  20)
           (SETQ R  4)
           (SETQ FR  3.67)
           (SETQ BUD (+ D 21))
           (SETQ BUD1 (+ D 15))
           (SETQ BUH 10)
           (SETQ BUR  4)
           (SETQ W 4  )
           (SETQ P 40)
)   )
(IF (AND (>= D 50) (< D 60))
    (PROGN (SETQ BD (+ D 6))
           (SETQ H  12)
           (SETQ M  25)
           (SETQ R  5)
           (SETQ FR  4.58)
           (SETQ BUD (+ D 26))
           (SETQ BUD1 (+ D 20))
           (SETQ BUH 12)
           (SETQ BUR  4)
           (SETQ W 4  )
           (SETQ P 50)
)   )
(IF (AND (>= D 60) (< D 70))
    (PROGN (SETQ BD (+ D 6))
           (SETQ H  15)
           (SETQ M  25)
           (SETQ R  5)
           (SETQ FR  4.58)
           (SETQ BUD (+ D 26))
           (SETQ BUD1 (+ D 20))
           (SETQ BUH 12)
           (SETQ BUR  4)
           (SETQ W 4  )
           (SETQ P 60)
)   )
(IF (AND (>= D 70) (< D 80))
    (PROGN
       (SETQ BD (+ D 6))
       (SETQ H  15)
       (SETQ M  25)
       (SETQ R  5)
       (SETQ FR  4.58)
       (SETQ BUD (+ D 26))
       (SETQ BUD1 (+ D 20))
       (SETQ BUH 12)
       (SETQ BUR  4)
       (SETQ W 4  )
       (SETQ P 70)
     )
)
(IF (= D 80)
    (PROGN
       (SETQ BD 86)
       (SETQ H  15)
       (SETQ M  25)
       (SETQ FR  4.58)
       (SETQ R  5)
       (SETQ BUD 105)
       (SETQ BUD1 100)
       (SETQ BUH 12)
       (SETQ BUR  4)
       (SETQ W 4  )
       (SETQ P 80)
     )
)
  (SETQ P1 (GETPOINT "\nP1:"))
  (SETQ P2 (GETPOINT P1 "\nP2:"))
  (SETQ P3 (GETPOINT P2 "\nP3:"))
   (SETQ LSE (DISTANCE P1 P3)) ;DIST FOR P1 P3
   (SETQ LST (DISTANCE P1 P2)) ;DIST FOR P1 P2
   (SETQ LS2 (DISTANCE P2 P3)) ;DIST FOR P2 P3
   (SETQ AG1 (ANGLE P1 P2))
   (SETQ AG2 (* PI 0.5))
   (SETQ DR1 (POLAR (POLAR P1 (+ AG1 AG2) (+ (/ BD 2.0) 1)) AG1 H))
   (SETQ DR2 (POLAR (POLAR P1 (- AG1 AG2) (+ (/ BD 2.0) 1)) AG1 H))
   (SETQ DR3 (POLAR P1 (+ AG1 AG2) (+ (/ BD 2.0) 1)   ) )
   (SETQ DR4 (POLAR P1 (- AG1 AG2) (+ (/ BD 2.0) 1)) )
   (SETQ DR5 (POLAR (POLAR P1 (+ AG1 AG2) (/ BD 2.0) ) AG1 H))
   (SETQ DR6 (POLAR (POLAR P1 (- AG1 AG2)  (/ BD 2.0) ) AG1 H))
   (SETQ DR7 (POLAR P1 (+ AG1 AG2) (/ BD 2.0) ) )
   (SETQ DR8 (POLAR P1 (- AG1 AG2) (/ BD 2.0) ) )
   (SETQ DR9 (POLAR (POLAR P1 (+ AG1 AG2) (/ D 2.0) ) AG1 (+ H 3) ))
   (SETQ DR10 (POLAR (POLAR P1 (- AG1 AG2) (/ D 2.0) ) AG1 (+ H 3) ))
   (SETQ DR11 (POLAR (POLAR P1 (+ AG1 AG2) (- (/ D 2.0) 0.5) ) AG1 (+ H 3) ))
   (SETQ DR12 (POLAR (POLAR P1 (- AG1 AG2) (- (/ D 2.0) 0.5) ) AG1 (+ H 3) ))
   (SETQ DR13 (POLAR (POLAR P1 (+ AG1 AG2) (- (/ D 2.0) 0.5) ) AG1  H ))
   (SETQ DR14 (POLAR (POLAR P1 (- AG1 AG2) (- (/ D 2.0) 0.5) ) AG1 H ))
   (SETQ DR15 (POLAR (POLAR P1 (+ AG1 AG2) (/ D 2.0) ) AG1 H ))
   (SETQ DR16 (POLAR (POLAR P1 (- AG1 AG2) (/ D 2.0) ) AG1 H ))
   (SETQ DR17 (POLAR (POLAR DR15 (+ AG1 AG2) 1.5 ) AG1 (- LSE H) ))
   (SETQ DR18 (POLAR (POLAR DR16 (- AG1 AG2) 1.5) AG1 (- LSE H) ))
   (SETQ DR19 (POLAR DR15 AG1 (- LSE H M 5)  ))
   (SETQ DR20 (POLAR DR16 AG1 (- LSE H M 5) ))
   (SETQ DR21 (POLAR DR19 AG1 M))
   (SETQ DR22 (POLAR DR20  AG1 M))
   (SETQ DRINT1 (POLAR DR19 (- AG1 0.0872665) 3))
   (SETQ DRINT2 (POLAR DR20 (+ AG1 0.0872665) 3))
   (SETQ INT1 (INTERS DR19 DRINT1  DR21 DR22 NIL))
   (SETQ INT2 (INTERS DR20 DRINT2  DR21 DR22 NIL))
;
;END OF GP
;
;START BUSH
   (SETQ DR23 (POLAR (POLAR P1 (+ AG1 AG2) (+ (/ D 2.0) 1.5))
                     AG1 (+ (* D 2) LST)))
   (SETQ DR24 (POLAR (POLAR P1 (- AG1 AG2) (+ (/ D 2.0) 1.5))
                     AG1 (+ (* D 2) LST)))
   (SETQ DR25 (POLAR DR23 (- AG1 AG2) 1.5 ))
   (SETQ DR26 (POLAR DR24 (+ AG1 AG2) 1.5))
   (SETQ DR27 (POLAR DR25 (+ AG1 AG2) (/ (- BUD1 D) 2)))
   (SETQ DR28 (POLAR DR26 (- AG1 AG2) (/ (- BUD1 D) 2) ))
   (SETQ DR29 (POLAR DR27 (- AG1 AG2) 1))
   (SETQ DR30 (POLAR DR28 (+ AG1 AG2) 1))
   (SETQ DR31 (POLAR DR27 AG1 -1))
   (SETQ DR32 (POLAR DR28 AG1 -1))
   (SETQ DR33 (POLAR DR25 AG1 (* BUR -1)))
   (SETQ DR34 (POLAR DR26 AG1 (* BUR -1)))
   (SETQ DR35 (POLAR DR25 (+ AG1 AG2) BUR))
   (SETQ DR36 (POLAR DR26 (- AG1 AG2) BUR ))
   (SETQ DR37 (POLAR (POLAR P1 (+ AG1 AG2) (+ (/ D 2.0) (/ (- BUD1 D) 2)))
                      AG1 LST))
   (SETQ DR38 (POLAR (POLAR P1 (- AG1 AG2) (+ (/ D 2.0) (/ (- BUD1 D) 2)))
                      AG1 LST))
   (SETQ DR39 (POLAR DR37 AG1 2))
   (SETQ DR40 (POLAR DR38 AG1 2))
   (SETQ DR41 (POLAR (POLAR DR37 (- AG1 AG2) 1) AG1 1))
   (SETQ DR42 (POLAR (POLAR DR38 (+ AG1 AG2) 1) AG1 1))
   (SETQ DR43 (POLAR DR25 AG1 (* (- (* D 2) 1) -1) ))
   (SETQ DR44 (POLAR DR26 AG1 (* (- (* D 2) 1) -1) ))
   (SETQ DR45 (POLAR DR43 (+ AG1 AG2) BUR))
   (SETQ DR46 (POLAR DR44 (- AG1 AG2) BUR))
   (SETQ DR47 (POLAR (POLAR DR45 (- AG1 AG2) BUR) AG1 BUR))
   (SETQ DR48 (POLAR (POLAR DR46 (+ AG1 AG2) BUR) AG1 BUR))
   (SETQ DR49 (POLAR DR43 AG1 -2))
   (SETQ DR50 (POLAR DR44 AG1 -2))

(SETQ DR51 (POLAR INT1 (- AG1 AG2) FR))
(SETQ DR52 (POLAR INT2 (+ AG1 AG2) FR))
(SETQ DR53 (POLAR INT1 (- AG1 (DTR 185)) 1.83))
(SETQ DR54 (POLAR INT2 (+ AG1 (DTR 185)) 1.83))

;
(IF  (= ANS1 "N")
     (COMMAND "LAYER" "SET" GPHID "")
     (COMMAND "LAYER" "SET" GPCNT "")
)
   (COMMAND "LINE" DR1 DR2 "")
   (COMMAND "LINE" DR1 DR3 "")
   (COMMAND "LINE" DR2 DR4 "")
   (COMMAND "LINE" DR5 DR7 "")
   (COMMAND "LINE" DR6 DR8 "")
   (COMMAND "LINE" DR9 DR10 "")
   (COMMAND "LINE" DR11 DR13 "")
   (COMMAND "LINE" DR12 DR14 "")
   (COMMAND "LINE" DR15 DR19 "")
   (COMMAND "LINE" DR16 DR20 "")
   (COMMAND "LINE" DR19 DR20 "")
   (COMMAND "LINE" DR19 DR53 "")
   (COMMAND "LINE" DR20 DR54 "")

(COMMAND "ARC" DR51 "E" DR53 "R" R)
(COMMAND "ARC" DR54 "E" DR52 "R" R)
;(COMMAND "ARC" DR17 "E" DR23 "R" BUR)
;(COMMAND "ARC" DR24 "E" DR18 "R" BUR)

   (COMMAND "LINE" DR25 DR27 "")
   (COMMAND "LINE" DR26 DR28 "")
   (COMMAND "LINE" DR29 DR31 "")
   (COMMAND "LINE" DR30 DR32 "")
   (COMMAND "ARC" DR33 "E" DR35 "R" BUR)
   (COMMAND "ARC" DR36 "E" DR34 "R" BUR)
   (COMMAND "LINE" DR27 DR37 "")
   (COMMAND "LINE" DR28 DR38 "")
   (COMMAND "LINE" DR39 DR41 DR43 "")
   (COMMAND "LINE" DR40 DR42 DR44 "")
   (COMMAND "ARC" DR45 "E" DR47 "R" BUR)
   (COMMAND "ARC" DR48 "E" DR46 "R" BUR)

   (IF (= ANS1 "Y")
       (COMMAND "TRIM" DR15 DR16 "" (POLAR P2 (+ AG1 AG2) 4) "")
   )

   (COMMAND "LINE" DR49 DR50 "")
   (COMMAND "LINE" DR51 DR52 "")

(SETQ NU 1)
(IF (> LS2 P)
    (PROGN
       (SETQ N (FIX (/ LS2 P)))
       (SETQ GP P)
       (REPEAT (- N 3)
          (SETQ BR1 (POLAR (POLAR P1 AG1 (- LSE P W 5)) (+ AG1 AG2) (/ D 2.0)))
          (SETQ BR2 (POLAR (POLAR P1 AG1 (- LSE P W 5)) (- AG1 AG2) (/ D 2.0)))
          (SETQ BR3 (POLAR (POLAR P1 AG1 (- LSE P 5)) (+ AG1 AG2) (/ D 2.0)))
          (SETQ BR4 (POLAR (POLAR P1 AG1 (- LSE P 5)) (- AG1 AG2) (/ D 2.0)))
;         (COMMAND "BREAK" BR1 "F" BR1 BR3)
;         (COMMAND "BREAK" BR2 "F" BR2 BR4)
          (COMMAND "ARC" BR1 "E" BR3 "R" 3)
          (COMMAND "ARC" BR4 "E" BR2 "R" 3)
          (COMMAND "LINE" BR1 BR2 "")
          (COMMAND "LINE" BR3 BR4 "")
          (SETQ NU (+ NU 1))
          (SETQ P (+ GP P))
          (IF (< (- LSE P) (+ LST 8))
              (SETQ N 1)
          )
       )
    )
)

(COMMAND "LINE" DR17 DR23 "")
(COMMAND "LINE" DR18 DR24 "")
(COMMAND "LAYER" "SET" GPCEN "")
(COMMAND "LINE" (POLAR P1 AG1 -1) (POLAR P1 AG1 (+ 1 LSE))  "")

;HERE IS TEXT
(COMMAND "LAYER" "SET" GPTXT "")
(SETQ NUM (GETSTRING T "\nHOW MANY GUPIDE PIN ?"))
(IF (OR (= NUM "") (= NUM "1"))
   (SETQ GPDIM (STRCAT GPDIM NUM ))
   (SETQ GPDIM (STRCAT GPDIM "(" NUM "X" ")"))
)

(IF (AND (< AG1 (* PI 0.75)) (>= AG1 0))
    (PROGN
       (SETQ TT1 (POLAR (POLAR P1 AG1 (+ H 5))  (+ AG1 AG2) 2))
       (SETQ TT2 (POLAR (POLAR P1 AG1 (+ H 5)) (- AG1 AG2) 5))
       (SETQ AG1T AG1)
    )
)
(IF (AND (>= AG1 (* 0.75 PI)) (< AG1 (* PI 1.5)))
    (PROGN
       (SETQ TT2 (POLAR (POLAR P1 AG1 (+ H 25))  (+ AG1 AG2) 5))
       (SETQ TT1 (POLAR (POLAR P1 AG1 (+ H 25)) (- AG1 AG2) 2))
       (SETQ AG1T (+ AG1 PI))
    )
)
(IF (AND (>= AG1 (* 1.5 PI)) (< AG1 (* PI 2.0)))
    (PROGN
       (SETQ TT1 (POLAR (POLAR P1 AG1 (+ H 5))  (+ AG1 AG2) 2))
       (SETQ TT2 (POLAR (POLAR P1 AG1 (+ H 5)) (- AG1 AG2) 5))
       (SETQ AG1T AG1 )
    )
)

(SETQ LONG1 (- (DISTANCE P1 P3) 5))
(SETQ LONG1 (FIX LONG1))
(SETQ LONG1 (RTOS LONG1 2 0))
(SETQ LP (GETVAR "LUPREC"))   ;LP DIGITAL
(SETQ D1 (RTOS D 2 LP))
(SETQ D11 (FIX (ATOF D1)))
(SETQ RET (- D D11))
(IF (OR (= RET 0) (= RET 0.0) (= RET 0.00))
    (PROGN
       (SETQ SR (- (STRLEN D1) LP 1))
       (SETQ D1 (SUBSTR D1 1 SR))
    )
)

(SETQ DIST1 (STRCAT "%%C" D1 "X" LONG1 "L"))
(COMMAND "TEXT" TT1 3.0 (RTD AG1T) GPDIM)
(COMMAND "TEXT" TT2 3.0 (RTD AG1T) DIST1)

(COMMAND "LAYER" "SET" NY "")
)
