(DEFUN C:RP1 ()
;SET LAYER
(COMMAND "SETVAR" "CMDECHO" 0)
(SETQ NY (GETVAR "CLAYER"))
;(IF (= (TYPE F1) 'FILE ) "YES"  (STOP))
;(IF (= (TYPE F2) 'FILE ) "YES" (STOP))
(setq RPSET (findfile "C:/ACAD/ACAD/SUPPORT/RP.SET"))
(IF (= RPSET NIL)
    (PROGN
       (PROMPT "\nPLEASE SETTING LAYER RETURN PIN :" )
       (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/RP.SET" "w"))
       (setq RPCNT (GETSTRING T"\nSETTING RETURN PIN  LAYER OF CONTNIUE LINE/<0>:"))
       (IF (= RPCNT "")
              (WRITE-LINE "0" FC)
              (WRITE-LINE RPCNT FC)
       )
       (setq RPCEN (GETSTRING T"\nSETTING RETURN PIN LAYER OF CENTER LINE/<CEN>:"))
       (IF (= RPCEN "")
              (WRITE-LINE "CEN" FC)
              (WRITE-LINE RPCEN FC)
       )
       (setq RPHID (GETSTRING T"\nSETTING RETURN PIN LAYER OF HIDDEN LINE/<HID>:"))
       (IF (= RPHID "")
              (WRITE-LINE "HID" FC)
              (WRITE-LINE RPHID FC)
       )
       (setq RPDIM (GETSTRING T"\nSETTING RETURN PIN LAYER OF DIMESION /<DIM1>:"))
       (IF (= RPDIM "")
              (WRITE-LINE "DIM1" FC)
              (WRITE-LINE RPDIM FC)
       )
       (setq RPTXT (GETSTRING T"\nSETTING GUIDE PIN LAYER OF TEXT /<TEXT>:"))
       (IF (= RPTXT "")
              (WRITE-LINE "TEXT" FC)
              (WRITE-LINE RPTXT FC)
       )
       (CLOSE FC)
    )
)

(IF (/= RPSET NIL)
    (PROGN
       (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/RP.SET" "r"))
       (SETQ RPCNT (READ-LINE FC))
       (SETQ RPCEN (READ-LINE FC))
       (SETQ RPHID (READ-LINE FC))
       (SETQ RPDIM (READ-LINE FC))
       (SETQ RPTXT (READ-LINE FC))
       (IF (OR (= RPCNT "") (= RPCEN "") (= RPHID "") (= RPDIM "") (= RPTXT "")
               (= RPCNT NIL) (= RPCEN NIL) (= RPHID NIL) (= RPDIM NIL) (= RPTXT NIL))
           (CLOSE FC)
       )
       (IF (OR (= RPCNT "") (= RPCEN "") (= RPHID "") (= RPDIM "") (= RPTXT "")
               (= RPCNT NIL) (= RPCEN NIL) (= RPHID NIL) (= RPDIM NIL) (= RPTXT NIL))
           (PROGN
              (PROMPT "\nPLEASE SETTING LAYER RETURN PIN :" )
              (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/RP.SET" "w"))
              (setq RPCNT (GETSTRING T"\nSETTING RETURN PIN  LAYER OF CONTNIUE LINE/<0>:"))
              (IF (= RPCNT "")
                  (WRITE-LINE "0" FC)
                  (WRITE-LINE RPCNT FC)
              )
              (setq RPCEN (GETSTRING T"\nSETTING RETURN PIN LAYER OF CENTER LINE/<CEN>:"))
              (IF (= RPCEN "")
                  (WRITE-LINE "CEN" FC)
                  (WRITE-LINE RPCEN FC)
              )
              (setq RPHID (GETSTRING T"\nSETTING RETURN PIN LAYER OF HIDDEN LINE/<HID>:"))
              (IF (= RPHID "")
                  (WRITE-LINE "HID" FC)
                  (WRITE-LINE RPHID FC)
              )
              (setq RPDIM (GETSTRING T"\nSETTING RETURN PIN LAYER OF DIMESION/<DIM1>:"))
              (IF (= RPDIM "")
                  (WRITE-LINE "DIM1" FC)
                  (WRITE-LINE RPDIM FC)
              )
              (setq RPTXT (GETSTRING T"\nSETTING RETURN PIN LAYER OF TEXT /<TEXT>:"))
              (IF (= RPTXT "")
                  (WRITE-LINE "TEXT" FC)
                  (WRITE-LINE RPTXT FC)
              )
           (CLOSE FC)
           )
       )
       (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/RP.SET" "r"))
       (SETQ RPCNT (READ-LINE FC))
       (SETQ RPCEN (READ-LINE FC))
       (SETQ RPHID (READ-LINE FC))
       (SETQ RPDIM (READ-LINE FC))
       (SETQ RPTXT (READ-LINE FC))
       (CLOSE FC)
       (PROMPT "\nR.P CONTINUE OF LAYER IS:" )(PROMPT RPCNT)(TERPRI)
       (PROMPT "\nR.P CENTER OF LAYER IS:" ) (PROMPT RPCEN)(TERPRI)
       (PROMPT "\nR.P HIDDEN OF LAYER IS:" ) (PROMPT RPHID)(TERPRI)
       (PROMPT "\nR.P DIMENSION OF LAYER IS:" ) (PROMPT RPDIM)(TERPRI)
       (PROMPT "\nR.P TEXT   OF LAYER IS:" ) (PROMPT RPTXT)(TERPRI)
    )
)

(SETQ ANS (strcase (GETSTRING "\nDO YOU WANT TO CHANGE LAST SETTING <Y/N> N:")))
(IF (= ANS "Y")
    (PROGN
       (PROMPT "\nPLEASE SETTING LAYER:" )
       (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/RP.SET" "w"))
       (PROMPT "\nR.P CONTINUE OF LAYER ")(PROMPT"<")(PROMPT RPCNT)(PROMPT">:")
       (setq RPCNT (GETSTRING T))
       (IF (= RPCNT "")
              (WRITE-LINE "0" FC)
              (WRITE-LINE RPCNT FC)
       )
       (PROMPT "\nR.P CENTER OF LAYER ")(PROMPT"<")(PROMPT RPCEN)(PROMPT">:")
       (setq RPCEN (GETSTRING T))
       (IF (= RPCEN "")
              (WRITE-LINE "CEN" FC)
              (WRITE-LINE RPCEN FC)
       )
       (PROMPT "\nR.P HIDDEN OF LAYER ")(PROMPT"<")(PROMPT RPHID)(PROMPT">:")
       (setq RPHID (GETSTRING T))
       (IF (= RPHID "")
              (WRITE-LINE "HID" FC)
              (WRITE-LINE RPHID FC)
       )
       (PROMPT "\nR.P DIMESION OF LAYER ")(PROMPT"<")(PROMPT RPDIM)(PROMPT">:")
       (setq RPDIM (GETSTRING T))
       (IF (= RPDIM "")
              (WRITE-LINE "DIM1" FC)
              (WRITE-LINE RPDIM FC)
       )
       (PROMPT "\nR.P TEXT OF LAYER " )(PROMPT"<")(PROMPT RPTXT)(PROMPT">:")
       (setq RPTXT (GETSTRING T))
       (IF (= RPTXT "")
              (WRITE-LINE "TEXT" FC)
              (WRITE-LINE RPTXT FC)
       )
       (CLOSE FC)
       (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/RP.SET" "r"))
       (SETQ RPCNT (READ-LINE FC))
       (SETQ RPCEN (READ-LINE FC))
       (SETQ RPHID (READ-LINE FC))
       (SETQ RPDIM (READ-LINE FC))
       (SETQ RPTXT (READ-LINE FC))
       (CLOSE FC)
       (PROMPT "\nR.P CONTINUE OF LAYER NOW IS:" )(PROMPT RPCNT)(TERPRI)
       (PROMPT "\nR.P CENTER   OF LAYER NOW IS:" ) (PROMPT RPCEN)(TERPRI)
       (PROMPT "\nR.P HIDDEN   OF LAYER NOW IS:" ) (PROMPT RPHID)(TERPRI)
       (PROMPT "\nR.P DIM      OF LAYER NOW IS:" ) (PROMPT RPDIM)(TERPRI)
       (PROMPT "\nR.P TEXT     OF LAYER NOW  IS:" ) (PROMPT RPTXT)(TERPRI)
  )
)



;THE POINT IS FIST COUNTER Y THEN X
(MENUCMD "S=RP")
;(COMMAND "UJ" "")
(GRAPHSCR) (TERPRI)
(SETQ D (GETREAL"\nSelect dim:"))
(IF  (= (SETQ ANS1 (GETSTRING "\nDOU YOU WANT TO TRIM P2 LINE:<Y>")) "")
     (SETQ ANS1 "Y"))
(SETQ ANS1 (STRCASE ANS1))
(IF (AND (>= D 8) (< D 10))
    (PROGN
       (SETQ BD (+ D 4))
       (SETQ H  8)
     )
)
(IF (AND (>= D 10) (< D 12))
    (PROGN
       (SETQ BD (+ D 5))
       (SETQ H  8)
     )
)
(IF (AND (>= D 12) (< D 15))
    (PROGN
       (SETQ BD (+ D 5))
       (SETQ H  8)
     )
)
(IF (AND (>= D 15) (< D 20))
    (PROGN
       (SETQ BD (+ D 5))
       (SETQ H  8)
     )
)
(IF (AND (>= D 20) (< D 25))
    (PROGN
       (SETQ BD (+ D 5))
       (SETQ H  8)
     )
)
(IF (AND (>= D 20) (< D 25))
    (PROGN
       (SETQ BD (+ D 5))
       (SETQ H  8)
     )
)
(IF (AND (>= D 25) (< D 30))
    (PROGN
       (SETQ BD (+ D 5))
       (SETQ H  8)
     )
)
(IF (AND (>= D 30) (< D 35))
    (PROGN
       (SETQ BD (+ D 5))
       (SETQ H  8)
     )
)
(IF (AND (>= D 35) (< D 40))
    (PROGN
       (SETQ BD (+ D 5))
       (SETQ H  8)
     )
)
(IF (= D 40)
    (PROGN
       (SETQ BD (+ D 5))
       (SETQ H  8)
     )
)
(SETQ P1 (GETPOINT "\nP1:"))
(SETQ P2 (GETPOINT P1 "\nP2:"))
(SETQ P3 (GETPOINT P2 "\nP3:"))
(SETQ P4 (GETPOINT P3 "\nP4:"))
(SETQ ag1 (ANGLE P1 P2))
(SETQ AG2 (* PI 0.5))
(SETQ DR1 (POLAR (POLAR P1 AG1 H) (+ AG1 AG2) (+ (/ BD 2.0) 1)))
(SETQ DR2 (POLAR (POLAR P1 AG1 H) (- AG1 AG2) (+ (/ BD 2.0) 1)))
(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 H) (+ AG1 AG2) (/ BD 2.0)))
(SETQ DR6 (POLAR (POLAR P1 AG1 H) (- AG1 AG2) (/ BD 2.0)))
(SETQ DR7 (POLAR P1 (+ AG1 AG2) (/ BD 2.0)))
(SETQ DR8 (POLAR P1 (- AG1 AG2) (/ BD 2.0)))
;
;ABOVE FIRST BOX
(SETQ LSE (DISTANCE P1 P4)) ;DIST FOR P1 P4
(SETQ LST (DISTANCE P1 P2)) ;DIST FOR P1 P2
(SETQ LS3 (DISTANCE P1 P3)) ;DIST FOR P1 P3
(SETQ LS4 (DISTANCE P3 P4)) ;DIST FOR P3 P4
;
(SETQ DR9 (POLAR (POLAR P1 AG1 (+ H 3))  (+ AG1 AG2) (/ D 2.0)))
(SETQ DR10 (POLAR (POLAR P1 AG1 (+ H 3)) (- AG1 AG2) (/ D 2.0)))
(SETQ DR11 (POLAR (POLAR P1 AG1 (+ H 3)) (+ AG1 AG2) (- (/ D 2.0) 0.5)))
(SETQ DR12 (POLAR (POLAR P1 AG1 (+ H 3)) (- AG1 AG2) (- (/ D 2.0) 0.5)))
(SETQ DR13 (POLAR (POLAR P1 AG1 H) (+ AG1 AG2) (- (/ D 2.0) 0.5)))
(SETQ DR14 (POLAR (POLAR P1 AG1 H) (- AG1 AG2) (- (/ D 2.0) 0.5)))
(SETQ DR15 (POLAR (POLAR P1 AG1 H ) (+ AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR16 (POLAR (POLAR P1 AG1 H ) (- AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR15-1 (POLAR (POLAR P1 AG1 LST) (+ AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR16-1 (POLAR (POLAR P1 AG1 LST) (- AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR17 (POLAR  DR9 AG1  (- LSE H 3)))
(SETQ DR18 (POLAR  DR10 AG1  (- LSE H 3)))
(SETQ DR19 (POLAR (POLAR P1 AG1 LS3) (+ AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR20 (POLAR (POLAR P1 AG1 LS3) (- AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR21 (POLAR (POLAR P1 AG1 (- LSE (* D 2))) (+ AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR22 (POLAR (POLAR P1 AG1 (- LSE (* D 2))) (- AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR23 (POLAR (POLAR P1 AG1 (- LSE (* D 2))) (+ AG1 AG2) (/ D 2.0)))
(SETQ DR24 (POLAR (POLAR P1 AG1 (- LSE (* D 2))) (- AG1 AG2) (/ D 2.0)))

(IF (= ANS1 "Y")
    (PROGN
       (SETQ P2N (POLAR P2 (+ AG1 AG2) 4))
       (COMMAND "SELECT" P2N "")
       (SETQ SA (SSGET "P" ))
       (SETQ N (SSLENGTH SA))
       (SETQ NA (ENTGET (SSNAME SA 0)))
       (SETQ NP11 (ASSOC 10 NA))
       (SETQ NP12 (ASSOC 11 NA))
       (SETQ LA1 (ASSOC 8 NA))
       (SETQ LA11 (CDR LA1))
       (SETQ NP1 (CDR NP11))
       (SETQ NP2 (CDR NP12))
       (SETQ TR1 NP1)
       (SETQ TR2 NP2)
       (COMMAND "ERASE" P2N "")
       (IF (> (CAR TR1) (CAR TR2))
          (PROGN
             (SETQ TR1 NP2)
             (SETQ TR2 NP1)
          )
       )
    )
)

(IF (= ANS1 "Y")
    (PROGN
       (SETQ P3N (POLAR P3 (+ AG1 AG2) 4))
       (COMMAND "SELECT" P3N "")
       (SETQ SA (SSGET "P" ))
       (SETQ N (SSLENGTH SA))
       (SETQ NA (ENTGET (SSNAME SA 0)))
       (SETQ NP11 (ASSOC 10 NA))
       (SETQ NP12 (ASSOC 11 NA))
       (SETQ LA2 (ASSOC 8 NA))
       (SETQ LA21 (CDR LA2))
       (SETQ NP1 (CDR NP11))
       (SETQ NP2 (CDR NP12))
       (SETQ TR3 NP1)
       (SETQ TR4 NP2)
       (COMMAND "ERASE" P3N "")
       (IF (> (CAR TR3) (CAR TR4))
          (PROGN
             (SETQ TR3 NP2)
             (SETQ TR4 NP1)
          )
       )
    )
)

(IF  (= ANS1 "N")
     (COMMAND "LAYER" "SET" RPHID "")
     (COMMAND "LAYER" "SET" RPCNT "")
)

(COMMAND "LINE" DR1 DR2 "")
(COMMAND "LINE" DR1 DR3 "")
(COMMAND "LINE" DR2 DR4 "")
(COMMAND "LINE" DR5 DR7 "")
(COMMAND "LINE" DR6 DR8 "")
;BOX ABOVE
(COMMAND "LINE" DR9 DR10 "")
(COMMAND "LINE" DR11 DR13 "")
(COMMAND "LINE" DR12 DR14 "")
(COMMAND "LINE" DR9 DR17 "")
(COMMAND "LINE" DR10 DR18 "")
(COMMAND "LINE" DR15 DR15-1 "")
(COMMAND "LINE" DR16 DR16-1 "")
(COMMAND "LINE" DR19 DR21 "")
(COMMAND "LINE" DR20 DR22 "")
(COMMAND "LINE" DR9 DR17 "")
(COMMAND "LINE" DR10 DR18 "")
(COMMAND "LINE" DR21 DR23 "")
(COMMAND "LINE" DR22 DR24 "")
(IF (= ANS1 "N")
    (COMMAND "LINE" DR23 DR24 "")
)
(IF (= ANS1 "Y")
    (PROGN
       (COMMAND "LAYER" "SET" LA11 "")
       (COMMAND "LINE" TR1 (POLAR (POLAR P1 AG1 LST) (+ AG1 AG2) (/ D 2.0)) "")
       (COMMAND "LINE" TR2 (POLAR (POLAR P1 AG1 LST) (- AG1 AG2) (/ D 2.0)) "")
       (COMMAND "LAYER" "SET" LA21 "")
       (COMMAND "LINE" TR3 (POLAR (POLAR P1 AG1 LS3) (+ AG1 AG2) (/ D 2.0)) "")
       (COMMAND "LINE" TR4 (POLAR (POLAR P1 AG1 LS3) (- AG1 AG2) (/ D 2.0)) "")
    )
)
(COMMAND "LAYER" "SET" RPCEN "")
(COMMAND "LINE" (POLAR P1 AG1 -1) (POLAR P1 AG1 (+ LSE 1)) "")
;HERE IS TEXT

(SETQ NUM (GETSTRING T "\nHOW MANY RETURN PIN ?"))
(IF (OR (= NUM "") (= NUM "1"))
   (SETQ RPDIMT " ")
   (SETQ RPDIMT (STRCAT "(" NUM "X" ")"))
)

(IF (< AG1 PI)
    (PROGN
       (SETQ TT1 (POLAR (POLAR P1 AG1 (- LSE 17))  (+ AG1 AG2) 3))
       (SETQ TT2 (POLAR (POLAR P1 AG1 20) (- AG1 AG2) -1))
;      (SETQ TT2 (POLAR (POLAR P2 AG1 1) (- AG1 AG2) -1))
       (SETQ AG1T AG1)
    )
)
(IF (>= AG1 PI)
    (PROGN
       (SETQ TT1 (POLAR (POLAR P1 AG1 (- LSE 17))  (- AG1 AG2) 3))
       (SETQ TT2 (POLAR (POLAR P2 AG1 15) (- AG1 AG2) +1))
       (SETQ AG1T (+ AG1 PI))
    )
)


(SETQ TT3 (POLAR  DR9 AG1  (- LSE H 3 10)))
(SETQ TT4 (POLAR  DR10 AG1 (- LSE H 3 10)))
(IF (<= D 15)
    (SETQ TT5 (POLAR (POLAR P1 AG1 (- LSE 11.5)) (- AG1T AG2) (+ (/ D 2.0) 6)))
    (SETQ TT5 (POLAR (POLAR P1 AG1 (- LSE 11.5)) (+ AG1T AG2) 5 ))
)
(SETQ LONG1 (- (DISTANCE P1 P4) 0))
(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" RPDIMT))

(COMMAND "LAYER" "SET" RPTXT "")
(COMMAND "TEXT" TT1 3.0 (RTD (- AG1T AG2)) "RP")
(COMMAND "TEXT" TT2 3.0 (RTD AG1T) DIST1)

(SETQ DD (STRCAT "%%C" D1))
(COMMAND "LAYER" "SET" RPDIM "")
(IF (< AG1 PI)
    (PROGN
      (COMMAND "DIM" "ALIGNED" TT3 TT4 TT3 "   " "EXIT")
      (COMMAND "TEXT" TT5 3.0 (RTD (- AG1T AG2)) DD)
    )
)
(IF (>= AG1 PI)
    (PROGN
      (COMMAND "DIM" "ALIGNED" TT3 TT4 TT4 "   " "EXIT")
      (COMMAND "TEXT" (POLAR TT5 AG1 3) 3.0 (RTD (- AG1T AG2)) DD)
    )
)
(COMMAND "LAYER" "SET" NY "")
)
