(DEFUN C:EJA()
;SET LAYER
(COMMAND "SETVAR" "CMDECHO" 0)
(SETQ NY (GETVAR "CLAYER"))
;(IF (= (TYPE F1) 'FILE ) "YES"  (STOP))
;(IF (= (TYPE F2) 'FILE ) "YES" (STOP))
(setq EJSET (findfile "C:/ACAD/ACAD/SUPPORT/EJ.SET"))
(IF (= EJSET NIL)
    (PROGN
       (PROMPT "\nPLEASE SETTING LAYER E.J PIN :" )
       (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/EJ.SET" "w"))
       (setq EJCNT (GETSTRING T"\nSETTING E.J PIN  LAYER OF CONTNIUE LINE/<draw>:"))
       (IF (= EJCNT "")
              (WRITE-LINE "draw" FC)
              (WRITE-LINE EJCNT FC)
       )
       (setq EJCEN (GETSTRING T"\nSETTING E.J PIN LAYER OF CENTER LINE/<CENTER>:"))
       (IF (= EJCEN "")
              (WRITE-LINE "CENTER" FC)
              (WRITE-LINE EJCEN FC)
       )
       (setq EJHID (GETSTRING T"\nSETTING E.J PIN LAYER OF HIDDEN LINE/<HIDDEN>:"))
       (IF (= EJHID "")
              (WRITE-LINE "HIDDEN" FC)
              (WRITE-LINE EJHID FC)
       )
       (setq EJDIM (GETSTRING T"\nSETTING E.J PIN LAYER OF DIMENSION LINE/<TEXT>:"))
       (IF (= EJDIM "")
              (WRITE-LINE "TEXT" FC)
              (WRITE-LINE EJDIM FC)
       )
       (CLOSE FC)
    )
)

(IF (/= EJSET NIL)
    (PROGN
       (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/EJ.SET" "r"))
       (SETQ EJCNT (READ-LINE FC))
       (SETQ EJCEN (READ-LINE FC))
       (SETQ EJHID (READ-LINE FC))
       (SETQ EJDIM (READ-LINE FC))
       (IF (OR (= EJCNT "") (= EJCEN "") (= EJHID "") (= EJDIM "")
               (= EJCNT NIL) (= EJCEN NIL) (= EJHID NIL) (= EJDIM NIL))
           (CLOSE FC)
       )
       (IF (OR (= EJCNT "") (= EJCEN "") (= EJHID "") (= EJDIM "")
               (= EJCNT NIL) (= EJCEN NIL) (= EJHID NIL) (= EJDIM NIL))
           (PROGN
              (PROMPT "\nPLEASE SETTING LAYER E.J PIN :" )
              (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/EJ.SET" "w"))
              (setq EJCNT (GETSTRING T"\nSETTING E.J PIN  LAYER OF CONTNIUE LINE/<DRAW>:"))
              (IF (= EJCNT "")
                  (WRITE-LINE "DRAW" FC)
                  (WRITE-LINE EJCNT FC)
              )
              (setq EJCEN (GETSTRING T"\nSETTING GUIDE PIN LAYER OF CENTER LINE/<CENTER>:"))
              (IF (= EJCEN "")
                  (WRITE-LINE "CENTER" FC)
                  (WRITE-LINE EJCEN FC)
              )
              (setq EJHID (GETSTRING T"\nSETTING E.J PIN LAYER OF HIDDEN LINE/<HIDDEN>:"))
              (IF (= EJHID "")
                  (WRITE-LINE "HIDDEN" FC)
                  (WRITE-LINE EJHID FC)
              )
              (setq EJDIM (GETSTRING T"\nSETTING E.J PIN LAYER OF DIMENSION /<TEXT>:"))
              (IF (= EJDIM "")
                  (WRITE-LINE "TEXT" FC)
                  (WRITE-LINE EJDIM FC)
              )
           (CLOSE FC)
           )
       )
       (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/EJ.SET" "r"))
       (SETQ EJCNT (READ-LINE FC))
       (SETQ EJCEN (READ-LINE FC))
       (SETQ EJHID (READ-LINE FC))
       (SETQ EJDIM (READ-LINE FC))
       (CLOSE FC)
       (PROMPT "\nE.J CONTINUE OF LAYER IS:" )(PROMPT EJCNT)(TERPRI)
       (PROMPT "\nE.J CENTER OF LAYER IS:" ) (PROMPT EJCEN)(TERPRI)
       (PROMPT "\nE.J HIDDEN OF LAYER IS:" ) (PROMPT EJHID)(TERPRI)
       (PROMPT "\nE.J DIMENSION OF LAYER IS:" ) (PROMPT EJDIM)(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/EJ.SET" "w"))
       (PROMPT "\nE.J CONTINUE OF LAYER " )(PROMPT"<")(PROMPT EJCNT)(PROMPT">:")
       (setq EJCNT (GETSTRING T))
       (IF (= EJCNT "")
              (WRITE-LINE "DRAW" FC)
              (WRITE-LINE EJCNT FC)
       )
       (PROMPT "\nE.J CENTER OF LAYER " )(PROMPT"<")(PROMPT EJCEN)(PROMPT">:")
       (setq EJCEN (GETSTRING T))
       (IF (= EJCEN "")
              (WRITE-LINE "CENTER" FC)
              (WRITE-LINE EJCEN FC)
       )
       (PROMPT "\nE.J HIDDEN OF LAYER " )(PROMPT"<")(PROMPT EJHID)(PROMPT">:")
       (setq EJHID (GETSTRING T))
       (IF (= EJHID "")
              (WRITE-LINE "HIDDEN" FC)
              (WRITE-LINE EJHID FC)
       )
       (PROMPT "\nE.J DIMENSION LAYER " )(PROMPT"<")(PROMPT EJDIM)(PROMPT">:")
       (setq EJDIM (GETSTRING T))
       (IF (= EJDIM "")
              (WRITE-LINE "TEXT" FC)
              (WRITE-LINE EJDIM FC)
       )
       (CLOSE FC)
       (SETQ FC (OPEN "C:/ACAD/ACAD/SUPPORT/EJ.SET" "r"))
       (SETQ EJCNT (READ-LINE FC))
       (SETQ EJCEN (READ-LINE FC))
       (SETQ EJHID (READ-LINE FC))
       (SETQ EJDIM (READ-LINE FC))
       (CLOSE FC)
       (PROMPT "\nE.J CONTINUE OF LAYER NOW IS:" )(PROMPT EJCNT)(TERPRI)
       (PROMPT "\nE.J CENTER   OF LAYER NOW IS:" ) (PROMPT EJCEN)(TERPRI)
       (PROMPT "\nE.J HIDDEN   OF LAYER NOW IS:" ) (PROMPT EJHID)(TERPRI)
       (PROMPT "\nE.J DIMENSION OF LAYER IS:" ) (PROMPT EJDIM)(TERPRI)
  )
)



;THE POINT IS FIST COUNTER Y THEN X
(COMMAND "LAYER" "SET" EJCNT "")
(MENUCMD "S=JP")
;(COMMAND "UJ" "")
(GRAPHSCR) (TERPRI)
(SETQ D (GETREAL"\nSelect dim:"))
(IF  (= (SETQ ANS1 (GETSTRING "\nDO YOU WANT TO TRIM LINE:<Y>")) "")
     (SETQ ANS1 "Y"))
(SETQ ANS1 (STRCASE ANS1))
(IF (AND (>= D 0) (< D 1.5))
    (PROGN
       (SETQ BD 4)
       (SETQ H  4)
     )
)
(IF (AND (>= D 1.5 ) (< D 3.5))
    (PROGN
       (SETQ BD 6)
       (SETQ H  4)
     )
)
(IF (AND (>= D 3.5 ) (< D 4))
    (PROGN
       (SETQ BD 7)
       (SETQ H  4)
     )
)
(IF (AND (>= D 4 ) (< D 4.5))
    (PROGN
       (SETQ BD 8)
       (SETQ H  6)
     )
)
(IF (AND (>= D 4.5 ) (< D 6))
    (PROGN
       (SETQ BD 9)
       (SETQ H  6)
     )
)
(IF (AND (>= D 6 ) (< D 7))
    (PROGN
       (SETQ BD 10)
       (SETQ H  6)
     )
)
(IF (AND (>= D 7 ) (< D 8))
    (PROGN
       (SETQ BD 11)
       (SETQ H  6)
     )
)
(IF (AND (>= D 8 ) (< D 9))
    (PROGN
       (SETQ BD 13)
       (SETQ H  8)
     )
)
(IF (AND (>= D 9 ) (< D 12))
    (PROGN
       (SETQ BD 15)
       (SETQ H  8)
     )
)
(IF (>= D 12 )
    (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:"))
(COMMAND "OSNAP" "NONE" )
(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 LS5 (DISTANCE P2 P3)) ;DIST FOR P2 P3
;
(SETQ DR9 (POLAR (POLAR P1 AG1  H )  (+ AG1 AG2) (/ D 2.0)))
(SETQ DR10 (POLAR (POLAR P1 AG1 H ) (- AG1 AG2) (/ D 2.0)))

(SETQ DR9-1 (POLAR (POLAR P1 AG1  LST )  (+ AG1 AG2) (/ D 2.0)))
(SETQ DR10-1 (POLAR (POLAR P1 AG1 LST ) (- AG1 AG2) (/ D 2.0)))
(SETQ DR9-2 (POLAR (POLAR P1 AG1  LS3 )  (+ AG1 AG2) (/ D 2.0)))
(SETQ DR10-2 (POLAR (POLAR P1 AG1 LS3 ) (- AG1 AG2) (/ D 2.0)))
(SETQ DR11 (POLAR (POLAR P1 AG1  LSE ) (+ AG1 AG2) (/ D 2.0)))
(SETQ DR12 (POLAR (POLAR P1 AG1  LSE ) (- AG1 AG2) (/ D 2.0)))
(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 LST) (+ AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR16 (POLAR (POLAR P1 AG1 LST) (- AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR17 (POLAR (POLAR P1 AG1 LS3) (+ AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR18 (POLAR (POLAR P1 AG1 LS3) (- AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR19 (POLAR (POLAR P1 AG1 (- LSE (* D 3))) (+ AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR20 (POLAR (POLAR P1 AG1 (- LSE (* D 3))) (- AG1 AG2) (+ (/ D 2.0) 0.5)))
(SETQ DR21 (POLAR (POLAR P1 AG1 (- LSE (* D 3))) (+ AG1 AG2) (/ D 2.0)))
(SETQ DR22 (POLAR (POLAR P1 AG1 (- LSE (* D 3))) (- 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 I 0)
       (SETQ NB (ASSOC 0 NA))
       (SETQ NA (ENTGET (SSNAME SA I)))
       (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 "N")
    (PROGN
       (SETQ P3N (POLAR P3 (+ AG1 AG2) 4))
       (COMMAND "SELECT" P3N "")
       (SETQ SA (SSGET "P" ))
       (SETQ N (SSLENGTH SA))
       (SETQ I 0)
       (SETQ NB (ASSOC 0 NA))
       (SETQ NA (ENTGET (SSNAME SA I)))
       (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" EJHID "")
     (COMMAND "LAYER" "SET" EJCNT "")
)
(COMMAND "LINE" DR1 DR2 "")
(COMMAND "LINE" DR1 DR3 "")
(COMMAND "LINE" DR2 DR4 "")
(COMMAND "LINE" DR5 DR7 "")
(COMMAND "LINE" DR6 DR8 "")
;BOX ABOVE
(COMMAND "LINE" DR13 DR15 "")
(COMMAND "LINE" DR14 DR16 "")
(COMMAND "LINE" DR17 DR19 "")
(COMMAND "LINE" DR18 DR20 "")
(IF  (= ANS1 "Y")
     (PROGN
        (COMMAND "LINE" DR19 DR21 "")
        (COMMAND "LINE" DR20 DR22 "")
        (COMMAND "LINE" DR9 DR11 "")
        (COMMAND "LINE" DR10 DR12 "")
     )
)
(IF (= ANS1 "N")
    (PROGN
       (COMMAND "LINE" DR9 DR9-1 "")
       (COMMAND "LINE" DR10 DR10-1 "")
       (COMMAND "LAYER" "SET" EJCNT "")
       (COMMAND "LINE" DR9-1 DR9-2 "")
       (COMMAND "LINE" DR10-1 DR10-2 "")
       (COMMAND "LAYER" "SET" EJHID "")
       (COMMAND "LINE" DR9-2 DR11 "")
       (COMMAND "LINE" DR10-2 DR12 "")
       (COMMAND "LINE" DR19 DR20 "")
    )
)
(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" EJCEN "")
(COMMAND "LINE" (POLAR P1 AG1 -2) (POLAR P1 AG1 (+ LSE 2)) "")
(COMMAND "LAYER" "SET" NY "")

;HERE IS TEXT

(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 DD (STRCAT "%%C" D1))

(IF (< AG1 PI)
    (PROGN
       (SETQ TT3 (POLAR (POLAR P1 AG1 (+ (/ LS5 2) LST)) (- AG1 AG2) (+ (/ D 2.0) 0)))
       (SETQ TT4 (POLAR (POLAR P1 AG1 (+ (/ LS5 2) LST)) (+ AG1 AG2) (+ (/ D 2.0) 0)))
       (SETQ AG1T AG1)
       (SETQ TT5 (POLAR (POLAR P1 AG1 (- (+ (/ LS5 2) LST) 1.5)) (- AG1T AG2) (+ (/ D 2.0) 5.5)))
    )
)
(IF (>= AG1 PI)
    (PROGN
       (SETQ TT3 (POLAR (POLAR P1 AG1 (+ (/ LS5 2) LST)) (+ AG1 AG2) (+ (/ D 2.0) 0)))
       (SETQ TT4 (POLAR (POLAR P1 AG1 (+ (/ LS5 2) LST)) (- AG1 AG2) (+ (/ D 2.0) 0)))
       (SETQ AG1T (+ AG1 PI))
       (SETQ TT5 (POLAR (POLAR P1 AG1 (+ (+ (/ LS5 2) LST) 1.5)) (- AG1T AG2) (+ (/ D 2.0) 5.5)))
    )
)


;(IF (>= D 15)
;    (SETQ TT5 (POLAR (POLAR P1 AG1 (- (+ (/ LS5 2) LST) 1.5)) (+ AG1T AG2) (+ (/ D 2.0) 5.5)))
;    (SETQ TT5 (POLAR (POLAR P1 AG1 (+ (+ (/ LS5 2) LST) 1.5)) (- AG1T AG2) (+ (/ D 2.0) 5.5)))
;)
(COMMAND "LAYER" "SET" EJDIM "")

(IF (< AG1 PI)
    (PROGN
      (COMMAND "DIM" "DIMSE1" ON "DIMSE2" ON)
      (COMMAND "ALIGNED" TT3 TT4 TT4 "  " "EXIT")
      (COMMAND "TEXT" TT5 3 (RTD (- AG1 AG2)) DD)
    )
)
(IF (>= AG1 PI)
    (PROGN
       (COMMAND "DIM" "DIMSE1" ON "DIMSE2" ON)
       (COMMAND "ALIGNED" TT3 TT4 TT4 "  " "EXIT")
       (COMMAND "TEXT" TT5 3.0 (RTD (- AG1T AG2)) DD)
    )
)
(COMMAND "LAYER" "SET" NY "")
)
