;**************** DETAIL ********************
;(IF (= (TYPE F1) 'FILE ) "YES"  (STOP))
;(IF (= (TYPE F2) 'FILE ) "YES" (STOP))
(DEFUN C:TE  ()
  (SETQ PNN NIL FIGC NIL FIGG NIL P1 NIL P2 NIL P3 NIL P4 NIL DELTA 0
        ps NIL PE NIL D NIL D1 NIL D2 NIL D3 NIL PN NIL
        V (DTR 45) VV (DTR 225)    )
  (SETQ ORGLAYER  (GETVAR "CLAYER"))
  (SETQ ORGANGDIR (GETVAR "ANGDIR"))
  (SETVAR "ANGDIR"    0)
  (SETVAR "HIGHLIGHT" 0)
  (SETVAR "CMDECHO"   0)

;****** SELECT OBJ & COPYING TO POSITION OF USER'S ******
  (SETQ C1 (ENTGET (CAR (ENTSEL"\n Select area by a CIRCLE:"))))
  (SETQ PPO (GETPOINT "\nCHOOSE ORIGIN POINT:"))
  (SETQ P  (GETPOINT "\n POINT of displacement"))
  (SETQ X  (GETreal "\n Scale factor: "))
  (SETQ CIRP (CDR (ASSOC 10 C1)) )
  (SETQ R (CDR (ASSOC 40 C1)) )
  (SETQ D ( SQRT (*  (* R R ) 2))  )
  (SETQ P1 (POLAR CIRP VV D))
  (SETQ P2 (POLAR CIRP V D))
  (SETQ PPN (POLAR P (ANGLE CIRP PPO) (* (DISTANCE CIRP PPO) X)))
  (COMMAND "COPY"  "C" P1 P2 "" CIRP P)
;****** EXPLODE & GET TRIM EDGE CIRCLE ******
  (SETQ P1 (POLAR P VV D))
  (SETQ P2 (POLAR P V D))
  (COMMAND "SCALE" "C" P1 P2 "" P X)
  (SETQ R (* R X))
  (SETQ D ( SQRT (*  (* R R) 2))  )
  (SETQ P1 (POLAR P VV D))
  (SETQ P2 (POLAR P V D))
  (SETQ FIGC (SSGET "C" P1 P2 ) )
  (SETQ W (SSLENGTH FIGC))
  (SETQ IND 0)
  (REPEAT W
   (SETQ FIGG (ENTGET (SSNAME FIGC IND)))
   (SETQ PNA (CDR (ASSOC 0 FIGG)))
   (SETQ PN  (CDR (ASSOC -1 FIGG)))

   (IF (OR (= PNA "POLYLINE") (= PNA "INSERT") (= PNA "POLYGON")
           (= PNA "BLOCK")  )
    (COMMAND "EXPLODE" PN)
   )

   (IF  (= PNA "CIRCLE" ) (PROGN
    (SETQ RA (CDR (ASSOC 40 FIGG)) )
    (IF (= RA R)
     (SETQ PNN PN  CIP0 (CDR (ASSOC 10 FIGG))
           X0 (CAR CIP0) Y0 (CADR CIP0) R0 RA
     )
    )
   ))
   (SETQ IND (+ IND 1))
  );ENDREPEAT

  (SETQ FIGC NIL)
  (SETQ FIGC (SSGET "C" P1 P2 ) )
  (SETQ W (SSLENGTH FIGC))
  (SETQ IND 0)
  (REPEAT  W
   (SETQ FIGG  (ENTGET (SSNAME FIGC IND)))
   (SETQ PN    (CDR (ASSOC -1 FIGG)))
   (SETQ NAMES (CDR (ASSOC 0 FIGG)))

   (IF (= NAMES "LINE" )
      (DA9LINESUB)
   ) ;ENDIF OF LINE

   (IF (AND (= NAMES "CIRCLE") (NOT (EQUAL PN PNN)) ) (PROGN
    (SETQ CIP1 (CDR (ASSOC 10 FIGG)))
    (SETQ R1 (CDR (ASSOC 40 FIGG)))
    (SETQ D12  (DISTANCE CIP1 CIP0))
    (IF (>= D12 (+ R1 R0)) (COMMAND "ERASE" PN "") )
    (IF (AND (< D12 (+ R1 R0))  (> D12 (- R0 R1))) (DA9CIRCLESUB) )
   ));ENDIF OF CIRCLE

   (IF  (= NAMES "ARC")  (PROGN
    (SETQ DA9ARCDELTA T)
    (SETQ CIP1 (CDR (ASSOC 10 FIGG)))
    (SETQ R1 (CDR (ASSOC 40 FIGG)))
    (SETQ R0F (ATOF (RTOS R0 2 5)))

    (SETQ ANGSS (CDR (ASSOC 50 FIGG)))
    (SETQ PSS (POLAR CIP1 ANGSS R1))
    (SETQ ANGSS (ATOF (RTOS ANGSS 2 5)))

    (SETQ ANGEO (CDR (ASSOC 51 FIGG)))
    (IF (< ANGEO ANGSS) (SETQ ANGEE (+ ANGEO (* 2 PI)))  (SETQ ANGEE ANGEO) )
    (SETQ PEE (POLAR CIP1 ANGEE R1))
    (SETQ ANGEO (ATOF (RTOS ANGEO 2 5)))
    (SETQ ANGEE (ATOF (RTOS ANGEE 2 5)))

    (SETQ ANGMM (/ (+ ANGSS ANGEE) 2) )
    (SETQ PMM (POLAR CIP1 ANGMM R1))
    (SETQ ANGMM (ATOF (RTOS ANGMM 2 5)))

    (SETQ D12 (ATOF (RTOS (DISTANCE CIP1 CIP0) 2 5)))
    (SETQ DSS (ATOF (RTOS (DISTANCE CIP0 PSS)  2 5)))
    (SETQ DEE (ATOF (RTOS (DISTANCE CIP0 PEE)  2 5)))
    (SETQ DMM (ATOF (RTOS (DISTANCE CIP0 PMM)  2 5)))

    (IF (>= D12 (+ R1 R0)) (PROGN
     (COMMAND "ERASE" PN "")
     (SETQ DA9ARCDELTA NIL )
    ))
    (IF (<= D12 (- R0 R1)) (SETQ DA9ARCDELTA NIL )  )

    (IF (AND (= DSS R0F) (= DEE R0F) (> DMM R0F) ) (progn
     (COMMAND "ERASE" PN "")
     (SETQ DA9ARCDELTA NIL )
    ))
    (IF (/= DA9ARCDELTA NIL) (DA9CIRCLESUB) )
   ));ENDIF OF ARC

   (IF (= NAMES "TEXT") (PROGN
    (SETQ A72 (CDR (ASSOC 72 FIGG)))

    (IF (OR (= A72 0.0) (= A72 3.0) (= A72 5.0)) (PROGN
     (SETQ A10 (ASSOC 10 FIGG))
     (SETQ A10X (CADR  A10))
     (SETQ A10Y (CADDR A10))
     (COMMAND "SCALE" PN "" (LIST A10X A10Y) (/ 1 x))
    ))
    (IF (OR (= A72 1.0) (= A72 2.0) (= A72 4.0)) (PROGN
     (SETQ A11 (ASSOC 11 FIGG))
     (SETQ A11X (CADR  A11))
     (SETQ A11Y (CADDR A11))
     (COMMAND "SCALE" PN "" (LIST A11X A11Y) (/ 1 x))
    ))
   ));ENDIF OF TEXT

       (SETQ IND (+ IND 1))
  );ENDREPEAT


  (SETVAR "HIGHLIGHT" 1)
  (SETVAR "CMDECHO"   1)
  (SETVAR "ANGDIR" ORGANGDIR)
  (COMMAND "LAYER" "S" ORGLAYER "")
  (PROMPT "\n JOB FINISH !!!")
;------------ AUTODIMENTION START -----------------
    (COND ((NULL C:MDIMCONT)
         (PROMPT "PLEASE WAIT... LOADING")
         (LOAD "C:/ACAD/LSP/AUTODIM")
         )
    )
   (SETQ PP1 (FINDFILE "C:/ACAD/HON/AUTODIM.SET"))
   (IF (= PP1 NIL)
       (PROGN
          (PROMPT "\nPLEASE SETTING SCALE,TEXT HIGHT,DIGITS:")
          (SETQ FC (OPEN "C:/ACAD/HON/AUTODIM.SET" "w"))
          (setq scal (getreal "\nPLEASE INPUT VALUE OF SCALE/<1>:"))
          (IF (= SCAL NIL)
              (WRITE-LINE "1.0" FC)
          )
          (IF (/= SCAL NIL)
              (PROGN
                  (SETQ SCAL (RTOS SCAL 2 2))
                  (WRITE-LINE SCAL FC)
              )
          )
          (setq txt (getreal "\nDIM TEXT HEIGHT:/<3.0>"))
          (IF (= TXT NIL)
              (WRITE-LINE "3.0" FC)
          )
          (IF (/= TXT NIL)
             (PROGN
                (SETQ TXT (RTOS TXT 2 2))
                (WRITE-LINE TXT FC)
              )
          )
          (setq a (getint "\nNUMBER OF DIGITS/<2>:"))
          (IF (= A NIL)
              (WRITE-LINE "2" FC)
           )
          (IF (/= A NIL)
              (PROGN
                 (SETQ A (ITOA A))
                 (WRITE-LINE A FC)
               )
          )
          (setq t1 (getreal "\nANGLE OF VALUE TO DIM:(EXMPLE 0=90ø,0.6=30ø,1=45ø,2=60ø) 0---2  <0.6>:"))
          (IF (= T1 NIL)
              (WRITE-LINE "1" FC)
          )
          (IF (/= T1 NIL)
              (PROGN
                 (SETQ T1 (RTOS T1 2 1))
                 (WRITE-LINE T1 FC)
               )
           )
           (setq bt (getreal "\nDISTANCE BETWEEN EXTENSION LINE AND SELECT POINT <1.0>:"))
           (IF (= BT NIL)
               (WRITE-LINE "1" FC)
           )
           (IF (/= BT NIL)
               (PROGN
                  (SETQ BT (RTOS BT 2 1))
                  (WRITE-LINE BT FC)
              )
           )
           (setq TS (getreal "\nDISTANCE BETWEEN EXTENSION LINE AND TEXT <2.0>:"))
           (IF (= TS NIL)
               (WRITE-LINE "2" FC)
           )
           (IF (/= TS NIL)
               (PROGN
                 (SETQ TS (RTOS TS 2 1))
                 (WRITE-LINE TS FC)
                )
           )

           (setq OVER (getSTRING T"\nVALUE OF OVER <+0.5>:"))
           (IF (= OVER "")
               (WRITE-LINE "+0.5" FC)
           )
           (IF (/= OVER "")
               (PROGN
                 (WRITE-LINE OVER FC)
                )
           )
           (setq UNDER (getSTRING T"\nVALUE OF UNDER <-0.5>:"))
           (IF (= UNDER "")
               (WRITE-LINE "-0.5" FC)
           )
           (IF (/= UNDER "")
               (PROGN
                 (WRITE-LINE UNDER FC)
                )
           )
           (setq DBOVER (getSTRING T"\nVALUE OF OVER AND UNDER<ñ0.5>:"))
           (IF (= DBOVER "")
               (WRITE-LINE "0.5" FC)
               (WRITE-LINE DBOVER FC)
           )
       (CLOSE FC)
       )
   )


;HERE
   (IF (/= PP1 NIL)
       (PROGN
          (SETQ FC (OPEN "C:/ACAD/HON/AUTODIM.SET" "r"))
          (SETQ SCAL (READ-LINE FC))
          (SETQ TXT  (READ-LINE FC))
          (SETQ A    (READ-LINE FC))
          (SETQ T1   (READ-LINE FC))
          (SETQ BT    (READ-LINE FC))
          (SETQ TS    (READ-LINE FC))
          (SETQ OVER  (READ-LINE FC))
          (SETQ UNDER (READ-LINE FC))
          (SETQ DBOVER (READ-LINE FC))
          (IF (OR (= SCAL "") (= TXT "") (= A "") (= T1 "") (= BT "") (= TS "") (= OVER "")(= UNDER "") (= DBOVER "")
              (= SCAL NIL) (= TXT NIL) (= A NIL) (= T1 NIL) (= BT NIL) (= TS NIL) (= OVER NIL)(= UNDER NIL)(= DBOVER NIL))
              (CLOSE FC)
          )
          (IF (OR (= SCAL "") (= TXT "") (= A "") (= T1 "") (= BT "") (= TS "")(= OVER "")(= UNDER "") (= DBOVER "")
              (= SCAL NIL) (= TXT NIL) (= A NIL) (= T1 NIL) (= BT NIL) (= TS NIL) (= OVER NIL)(= UNDER NIL)(= DBOVER NIL))
              (PROGN
                 (PROMPT "\nPLEASE AUTODIM VALUE:" )
                 (SETQ FC (OPEN "C:/ACAD/HON/AUTODIM.SET" "w"))
                 (setq SCAL (GETREAL"\nSETTING SCALE/<1>:"))
                 (IF (= SCAL NIL NIL)
                     (WRITE-LINE "1.0" FC)
                 )
                 (IF (/= SCAL NIL)
                     (PROGN
                       (SETQ SCAL (RTOS SCAL 2 2))
                       (WRITE-LINE SCAL FC)
                     )
                 )
                 (setq txt (getreal "\nDIM TEXT HEIGHT:/<3.0)"))
                 (IF (= TXT NIL)
                     (WRITE-LINE "3.0" FC)
                 )
                 (IF (/= TXT NIL)
                     (PROGN
                       (SETQ TXT (RTOS TXT 2 2))
                       (WRITE-LINE TXT FC)
                     )
                 )
                 (setq a (getint "\nNUMBER OF DIGITS/<2>:"))
                 (IF (= A NIL)
                     (WRITE-LINE "2" FC)
                 )
                 (IF (/= A NIL)
                     (PROGN
                       (SETQ A (ITOA A))
                       (WRITE-LINE A FC)
                     )
                 )
                 (setq t1 (getreal "\nANGLE OF VALUE TO DIM:(EXMPLE 0=90ø,0.6=30ø,1=45ø,2=60ø) 0---2  <0.6>:"))
                 (IF (= T1 NIL)
                     (WRITE-LINE "1" FC)
                 )
                 (IF (/= T1 NIL)
                     (PROGN
                        (SETQ T1 (RTOS T1 2 1))
                        (WRITE-LINE T1 FC)
                      )
                 )
                 (setq bt (getreal "\nDISTANCE BETWEEN EXTENSION LINE AND SELECT POINT <1.0>:"))
                 (IF (= BT NIL)
                    (WRITE-LINE "1" FC)
                 )
                 (IF (/= BT NIL)
                     (PROGN
                        (SETQ BT (RTOS BT 2 1))
                        (WRITE-LINE BT FC)
                     )
                 )
                 (setq TS (getreal "\nDISTANCE BETWEEN EXTENSION LINE AND TEXT <2.0>:"))
                 (IF (= TS NIL)
                     (WRITE-LINE "2" FC)
                 )
                 (IF (/= TS NIL)
                     (PROGN
                        (SETQ TS (RTOS TS 2 1))
                        (WRITE-LINE TS FC)
                        (SETQ TEST 1)
                     )
                 )
                 (setq OVER (getSTRING T "\nVALUE OF OVER <+0.5>:"))
                 (IF (= OVER "")
                     (WRITE-LINE "+0.5" FC)
                 )
                 (IF (/= OVER "")
                     (PROGN
                       (WRITE-LINE OVER FC)
                      )
                 )
                 (setq UNDER (getSTRING T "\nVALUE OF UNDER <-0.5>:"))
                 (IF (= UNDER "")
                     (WRITE-LINE "-0.5" FC)
                 )
                 (IF (/= UNDER "")
                     (PROGN
                       (WRITE-LINE UNDER FC)
                      )
                 )
                 (setq DBOVER (getSTRING T "\nVALUE OF OVER AND UNDER<ñ0.5>:"))
                 (IF (= DBOVER "")
                     (WRITE-LINE "0.5" FC)
                 )
                 (IF (/= DBOVER "")
                     (PROGN
                       (WRITE-LINE DBOVER FC)
                      )
                 )
                 (CLOSE FC)
              )
          )
      )
   )

    (SETQ FR (OPEN "C:/ACAD/HON/AUTODIM.SET" "r"))
    (SETQ SCAL (READ-LINE FR))
    (SETQ SCAL (ATOF SCAL))
    (SETQ TXT (READ-LINE FR))
    (SETQ TXT (ATOF TXT))
    (SETQ A (READ-LINE FR))
    (SETQ A (ATOI A))
    (SETQ T1 (READ-LINE FR))
    (SETQ T1 (ATOF T1))
    (SETQ BT (READ-LINE FR))
    (SETQ BT (ATOF BT))
    (SETQ TS (READ-LINE FR))
    (SETQ TS (ATOF TS))
    (SETQ OVER (READ-LINE FR))
    (SETQ UNDER (READ-LINE FR))
    (SETQ DBOVER (READ-LINE FR))
    (CLOSE FR)
    (PROMPT "\nDIM SCALE IS:" )(PRIN1 SCAL)(TERPRI)
    (PROMPT "\nDIM TEXT HEIGHT IS:") (PRIN1 TXT)(TERPRI)
    (PROMPT "\nNUMBER OF DIGITS IS:") (PRIN1 A)(TERPRI)
    (PROMPT "\nANGLE OF VALUE IS:") (PRIN1 T1)(TERPRI)
    (PROMPT "\nDISTANCE BETWEEN EXTENSION LINE AND SELECT POINT IS:" ) (PRIN1 BT)(TERPRI)
    (PROMPT "\nDISTANCE BETWEEN EXTENSION LINE AND TEXT IS:" ) (PRIN1 TS)(TERPRI)
    (PROMPT "\nVALUE OF OVER IS:") (PRIN1 OVER)(TERPRI)
    (PROMPT "\nVALUE OF UNDER IS:" ) (PRIN1 UNDER)(TERPRI)
    (PROMPT "\nVALUE OF OVER AND UNDER IS:" ) (PRIN1 UNDER)(TERPRI)
;*--------------SHOW SETTING --------------
  (SETQ ANS (strcase (GETSTRING"\nDO YOU WANT TO CHANGE LAST SETTING <Y/N> N:")))
  (IF (= ANS "Y")  (PROGN
    (PROMPT "\nPLEASE SETTING SCALE,TEXTHIGHT,DIGITS:" )
    (SETQ FC (OPEN "C:/ACAD/HON/AUTODIM.SET" "w"))
    (PROMPT "\nSCALE IS:" )(PRIN1 SCAL)(TERPRI)

    (setq scal (getreal "\nPLEASE INPUT VALUE OF SCALE/<1>:"))
    (IF (= SCAL NIL)
      (WRITE-LINE "1" FC)
    )
    (IF (/= SCAL NIL) (PROGN
      (SETQ SCAL (RTOS SCAL 2 2))
      (WRITE-LINE SCAL FC)
    ))

    (PROMPT "\nDIM TEXT HEIGHT IS:" )(PRIN1 TXT)(TERPRI)
    (setq txt (getreal "\nDIM TEXT HEIGHT:/<3.0>"))
    (IF (= TXT NIL)
      (WRITE-LINE "3.0" FC)
    )
    (IF (/= TXT NIL) (PROGN
      (SETQ TXT (RTOS TXT 2 2))
      (WRITE-LINE TXT FC)
    ))

    (PROMPT "\nNUMBER OF DIGITS IS:" )(PRIN1 A)(TERPRI)
    (setq a (getint "\nNUMBER OF DIGITS/<2>:"))
    (IF (= A NIL)
      (WRITE-LINE "2" FC)
     )
    (IF (/= A NIL) (PROGN
      (SETQ A (ITOA A))
      (WRITE-LINE A FC)
    ))

    (PROMPT "\nANGLE VALUE IS:" )(PRIN1 T1)(TERPRI)
    (setq t1 (getreal "\nANGLE OF VALUE TO DIM:(EXMPLE 0=90ø,0.6=30ø,1=45ø,2=60ø) 0---2  <0.6>:"))
    (IF (= T1 NIL)
      (WRITE-LINE "1" FC)
    )
    (IF (/= T1 NIL) (PROGN
      (SETQ T1 (RTOS T1 2 1))
      (WRITE-LINE T1 FC)
    ))

    (PROMPT "\nDISTANCE BETWEEN EXTENSION LINE AND SELECT POINT IS:" )(PRIN1 BT)(TERPRI)
    (setq bt (getreal "\nDISTANCE BETWEEN EXTENSION LINE AND SELECT POINT <1.0>:"))
    (IF (= BT NIL)
      (WRITE-LINE "1" FC)
    )
    (IF (/= BT NIL) (PROGN
      (SETQ BT (RTOS BT 2 1))
      (WRITE-LINE BT FC)
    ))

    (PROMPT "\nDISTANCE BETWEEN EXTENSION LINE AND TEXT IS:" )(PRIN1 TS)(TERPRI)
    (setq TS (getreal "\nDISTANCE BETWEEN EXTENSION LINE AND TEXT <2.0>:"))
    (IF (= TS NIL)
      (WRITE-LINE "2" FC)
    )
    (IF (/= TS NIL) (PROGN
      (SETQ TS (RTOS TS 2 1))
      (WRITE-LINE TS FC)
      (SETQ TEST 1)
    ))

    (PROMPT "\nVALUE OF OVER IS:" )(PRIN1 OVER)(TERPRI)
    (setq OVER (getSTRING T "\nVALUE OF OVER <+0.5>:"))
    (IF (= OVER "")
      (WRITE-LINE "+0.5" FC)
    )
    (IF (/= OVER "")
      (WRITE-LINE OVER FC)
    )

    (PROMPT "\nVALUE OF UNDER IS:" )(PRIN1 UNDER)(TERPRI)
    (setq UNDER (getSTRING T "\nVALUE OF UNDER <-0.5>:"))
    (IF (= UNDER "")
      (WRITE-LINE "-0.5" FC)
    )
    (IF (/= UNDER "")
      (WRITE-LINE UNDER FC)
    )

    (PROMPT "\nVALUE OF OVER AND UNDER IS:" )(PRIN1 DBOVER)(TERPRI)
    (setq DBOVER (getSTRING T "\nVALUE OF OVER AND UNDER<ñ0.5>:"))
    (IF (= DBOVER "")
      (WRITE-LINE "0.5" FC)
    )
    (IF (/= DBOVER "")
      (WRITE-LINE DBOVER FC)
    )
          (CLOSE FC)
    (SETQ FR (OPEN "C:/ACAD/HON/AUTODIM.SET" "r"))
    (SETQ SCAL (READ-LINE FR))
    (SETQ SCAL (ATOF SCAL))
    (SETQ TXT (READ-LINE FR))
    (SETQ TXT (ATOF TXT))
    (SETQ A (READ-LINE FR))
    (SETQ A (ATOI A))
    (SETQ T1 (READ-LINE FR))
    (SETQ T1 (ATOF T1))
    (SETQ BT (READ-LINE FR))
    (SETQ BT (ATOF BT))
    (SETQ TS (READ-LINE FR))
    (SETQ TS (ATOF TS))
    (SETQ OVER (READ-LINE FR))
    (SETQ UNDER (READ-LINE FR))
    (SETQ DBOVER (READ-LINE FR))
    (CLOSE FR)
    (PROMPT "SCALE IS:" )(PRIN1 SCAL)(TERPRI)
    (PROMPT "DIM TEXT HEIGHT NOW IS:" )(PRIN1 TXT)(TERPRI)
    (PROMPT "NUMBER OF DIGITS NOW IS:" )(PRIN1 A)(TERPRI)
    (PROMPT "ANGLE VALUE NOW IS:" )(PRIN1 T1)(TERPRI)
    (PROMPT "DISTANCE BETWEEN EXTENSION LINE AND SELECT POINT IS NOW :" )(PRIN1 BT)(TERPRI)
    (PROMPT "DISTANCE BETWEEN EXTENSION LINE AND TEXT NOW IS:" )(PRIN1 TS)(TERPRI)
    (PROMPT "VALUE OF OVER NOW IS:" )(PRIN1 OVER)(TERPRI)
    (PROMPT "VALUE OF UNDER NOW IS:" )(PRIN1 UNDER)(TERPRI)
    (PROMPT "VALUE OF OVER AND UNDER NOW IS:" )(PRIN1 DBOVER)(TERPRI)

  )) ;ENDIF OF ANS=Y

    (EXTLI)
    (SETQ SCAL (* SCAL X))
    (SETQ OP PPN)
);ENDDEFUN
;
;================================================================
  (DEFUN DA9LINESUB ()
    (SETQ PN  (CDR (ASSOC -1 FIGG)))
    (SETQ PST (CDR (ASSOC 10 FIGG)))
    (SETQ PET (CDR (ASSOC 11 FIGG)))
    (SETQ X1 (CAR  PST ))
    (SETQ Y1 (CADR PST ))
    (SETQ X2 (CAR  PET ))
    (SETQ Y2 (CADR PET ))
    (SETQ Y2Y1 (ATOF (RTOS (- Y2 Y1)2 4)))

    (IF (= Y2Y1 0) (PROGN
     (SETQ B (* -2 X0))
     (SETQ C (+ (* X0 X0) (* (- Y1 Y0) (- Y1 Y0)) (* -1 R0 R0)))
     (SETQ DELTA (- (* B B) (* 4 C)))
     (IF (< DELTA 0) (COMMAND "ERASE" PN ""))
     (IF (>= DELTA 0) (PROGN
      (SETQ XA1 (/ (+ (* -1 B) (SQRT DELTA)) 2))
      (SETQ XA2 (/ (- (* -1 B) (SQRT DELTA)) 2))
      (SETQ PLL1 (LIST XA1 Y1))
      (SETQ PLL2 (LIST XA2 Y1))
        (DA9LINESUB-1)
     ))
    ))

    (IF (/= Y2Y1 0) (PROGN
     (SETQ A (- Y2 Y1))
     (SETQ B (- X2 X1))

     (SETQ AA (/ B A))
     (SETQ BB (- X1 (* AA Y1)))

     (SETQ A- (+ (* AA AA) 1))
     (SETQ B- (* 2 (- (* BB AA) (* X0 AA) Y0)))
     (SETQ C- (+ (* BB BB) (* -2 X0 BB) (* X0 X0) (* Y0 Y0) (* -1 R0 R0)))

     (SETQ DELTA (- (* B- B-) (* 4 A- C-)))
     (IF (< DELTA 0) (COMMAND "ERASE" PN ""))
     (IF (>= DELTA 0) (PROGN
      (SETQ YA  (/ (+ (* -1 B-) (SQRT DELTA)) (* 2 A-) ))
      (SETQ YB  (/ (- (* -1 B-) (SQRT DELTA)) (* 2 A-) ))
      (SETQ XA (+ (* YA (/ B A)) (- X1 (* Y1 (/ B A))) ))
      (SETQ XB (+ (* YB (/ B A)) (- X1 (* Y1 (/ B A))) ))
      (SETQ PLL1 (LIST XA  YA))
      (SETQ PLL2 (LIST XB  YB))
        (DA9LINESUB-1)
     ))
    ))

  );ENDDEFUN OF LINE
  ;-----------------------------------------------------------
  (DEFUN DA9LINESUB-1 ()
    (SETQ TESTBA (ABS (- (ANGLE PLL1 PLL2) (ANGLE PST PET))))
    (SETQ TESTCA (ABS (- (ANGLE PLL2 PLL1) (ANGLE PST PET))))
    (IF (< TESTBA TESTCA) (SETQ PLLS PLL1 PLLE PLL2) (SETQ PLLS PLL2 PLLE PLL1) )

    (IF (AND (>= (DISTANCE P PST) R0) (>= (DISTANCE P PET) R0) ) (PROGN
      (IF (OR (> (DISTANCE PST PLLS) (DISTANCE PST PET))
              (> (DISTANCE PET PLLE) (DISTANCE PET PST)) )
        (COMMAND "ERASE" PN "")
        (PROGN
         (SETQ FIGG (SUBST (CONS 10 PLLS) (ASSOC 10 FIGG) FIGG))
         (SETQ FIGG (SUBST (CONS 11 PLLE) (ASSOC 11 FIGG) FIGG))
         (ENTMOD FIGG)
      ))
    ))

    (IF (AND (>= (DISTANCE P PST) R0) (<= (DISTANCE P PET) R0) )
     (ENTMOD (SUBST (CONS 10 PLLS) (ASSOC 10 FIGG) FIGG))
    )
    (IF (AND (<= (DISTANCE P PST) R0) (>= (DISTANCE P PET) R0) )
     (ENTMOD (SUBST (CONS 11 PLLE) (ASSOC 11 FIGG) FIGG))
    )

   );ENDDEFUN OF LINESUB-1
  ;=============================================
   (DEFUN DA9CIRCLESUB ()
    (SETQ AA NIL BB NIL CC NIL DELTX NIL DELTY NIL DELTA0 NIL DELTA1 NIL
          ANS1 NIL ANS2 NIL ANS3 NIL ANS4 NIL INP1 NIL INP2 NIL INP3 NIL
    )
    (SETQ X1 (CAR CIP1))
    (SETQ Y1 (CADR CIP1))
    (SETQ AA (ATOF (RTOS (* 2 (- X1 X0) ) 2 5 ) ) )
    (SETQ BB (ATOF (RTOS (* 2 (- Y1 Y0) ) 2 5 ) ) )
    (SETQ CC (+ (* X0 X0) (* X1 X1 -1) (* Y0 Y0) (* Y1 Y1 -1) (* R1 R1) (* R0 R0 -1) ) )
    (IF (= AA 0) (PROGN
     (SETQ YA (/ (* -1 CC) BB))
     (SETQ A-  1)
     (SETQ B- (* -2 X0))
     (SETQ C- (+ (* X0 X0) (* (- YA Y0) (- YA Y0)) (* -1 R0 R0)))
     (SETQ DELTX  (- (* B- B-) (* 4 A- C-) ))
     (IF (>= DELTX 0) (PROGN
      (SETQ DELTX (SQRT DELTX))
      (SETQ XA1 (/ (+ (* -1 B-) DELTX) 2))
      (SETQ XA2 (/ (- (* -1 B-) DELTX) 2))
      (SETQ INP1  (LIST XA1 YA))
      (SETQ INP2  (LIST XA2 YA))
     ))
    ))
    (IF (/= AA 0) (PROGN
     (SETQ A- (+ (/ (* BB BB) (* AA AA)) 1))
     (SETQ B- (* 2 (+ (/ (* BB CC) (* AA AA))  (/ (* X0 BB) AA)  (* -1 Y0))))
     (SETQ C- (+ (/ (* CC CC) (* AA AA))  (/ (* 2 X0 CC) AA) (* X0 X0) (* Y0 Y0) (* -1 R0 R0) ))
     (SETQ DELTY  (- (* B- B-) (* 4 A- C-) ))
     (IF (>= DELTY 0) (PROGN
      (SETQ DELTY (SQRT DELTY))
      (SETQ YA  (/ (+ (* -1 B-) DELTY) (* 2 A-) ))
      (SETQ YB  (/ (- (* -1 B-) DELTY) (* 2 A-) ))
      (SETQ A 1)
      (SETQ B (* -2 X0))
      (SETQ C (+ (* X0 X0) (* (- YA Y0) (- YA Y0)) (* -1 R0 R0)))
      (SETQ DELTA0 (- (* B B) (* 4 A C)))
      (IF (>= DELTA0 0) (PROGN
       (SETQ XA1 (/ (+ (* -1 B) (SQRT DELTA0)) 2))
       (SETQ XA2 (/ (- (* -1 B) (SQRT DELTA0)) 2))
       (SETQ ANS1 (ATOF (RTOS (+ (* (- XA1 X1) (- XA1 X1)) (* (- YA Y1) (- YA Y1)) (* -1 R1 R1) ) 2 4)))
       (SETQ ANS2 (ATOF (RTOS (+ (* (- XA2 X1) (- XA2 X1)) (* (- YA Y1) (- YA Y1)) (* -1 R1 R1) ) 2 4)))
       (IF (< (ABS ANS1) (ABS ANS2))
        (SETQ INP1  (LIST XA1 YA))
        (SETQ INP1  (LIST XA2 YA))
       )
      ))

      (SETQ C (+ (* X0 X0) (* (- YB Y0) (- YB Y0)) (* -1 R0 R0)))
      (SETQ DELTA1 (- (* B B) (* 4 A C)))
      (IF (>= DELTA1 0) (PROGN
       (SETQ XB1 (/ (+ (* -1 B) (SQRT DELTA1)) 2))
       (SETQ XB2 (/ (- (* -1 B) (SQRT DELTA1)) 2))
       (SETQ ANS3 (ATOF (RTOS (+ (* (- XB1 X1) (- XB1 X1)) (* (- YB Y1) (- YB Y1)) (* -1 R1 R1) ) 2 4)))
       (SETQ ANS4 (ATOF (RTOS (+ (* (- XB2 X1) (- XB2 X1)) (* (- YB Y1) (- YB Y1)) (* -1 R1 R1) ) 2 4)))
       (IF (< (ABS ANS3) (ABS ANS4))
        (SETQ INP2  (LIST XB1 YB))
        (SETQ INP2  (LIST XB2 YB))
       )
      ))
     ))
    ))
    (IF (AND (= NAMES "CIRCLE" ) (/= INP1 NIL) (/= INP2 NIL) )
     (PROGN
      (SETQ INP3 (POLAR CIP1 (ANGLE CIP1 CIP0) R1))
      (COMMAND "LAYER" "S"  (CDR (ASSOC 8 FIGG)) "")
      (COMMAND "ERASE" PN "")
      (COMMAND "ARC" INP1 INP3 INP2 )
    ))

    (IF (AND (= NAMES "ARC") (/= INP1 NIL) (/= INP2 NIL)) (DA9ARCALFA))
  );ENDDEFUN OF DA9CIRCLESUB
  ;-----------------------------------------------------------
  (DEFUN DA9ARCALFA ()
    (SETQ ANGP1 (ATOF (RTOS (ANGLE CIP1 INP1) 2 5)))
    (SETQ ANGP2 (ATOF (RTOS (ANGLE CIP1 INP2) 2 5)))
    (SETQ PAA (POLAR CIP1 (ANGLE CIP0 CIP1) R1))
    (SETQ ANGPA (ATOF (RTOS (ANGLE CIP0 PAA) 2 5)))
    (IF (> ANGEE (DTR 360)) (PROGN
     (IF (AND (>= ANGEO ANGP1) (>= ANGP1 (DTR 0)))
      (SETQ ANGP1 (ATOF (RTOS (+ ANGP1 (DTR 360)) 2 5))))
     (IF (AND (>= ANGEO ANGP2) (>= ANGP2 (DTR 0)))
      (SETQ ANGP2 (ATOF (RTOS (+ ANGP2 (DTR 360)) 2 5))))
     (IF (AND (>= ANGEO ANGPA) (>= ANGPA (DTR 0)))
      (SETQ ANGPA (ATOF (RTOS (+ ANGPA (DTR 360)) 2 5))))
    ))
  ;
    (IF (AND (>= ANGP1 ANGSS) (<= ANGP1 ANGEE) (>= ANGP2 ANGSS) (<= ANGP2 ANGEE))
     (PROGN
      (IF (< ANGP1 ANGP2) (SETQ ANGPS ANGP1 INPS INP1 ANGPE ANGP2 INPE INP2))
      (IF (> ANGP1 ANGP2) (SETQ ANGPS ANGP2 INPS INP2 ANGPE ANGP1 INPE INP1))
      (IF (= ANGP1 ANGP2) (SETQ ANGPS ANGP1 INPS INP1 ANGPE NIL   INPE NIL ))
    ))
  ;
    (IF (AND (AND (>= ANGP1 ANGSS) (<= ANGP1 ANGEE))
             (OR  (<  ANGP2 ANGSS) (>  ANGP2 ANGEE)) )
     (SETQ ANGPS ANGP1 INPS INP1 ANGPE NIL INPE NIL)
    )
    (IF (AND (AND (>= ANGP2 ANGSS) (<= ANGP2 ANGEE))
             (OR  (<  ANGP1 ANGSS) (>  ANGP1 ANGEE)) )
     (SETQ ANGPS ANGP2 INPS INP2 ANGPE NIL INPE NIL)
    )
    (IF (AND (OR  (<  ANGP1 ANGSS) (>  ANGP1 ANGEE))
             (OR  (<  ANGP2 ANGSS) (>  ANGP2 ANGEE)) )
     (SETQ ANGPS NIL  INPS NIL  ANGPE NIL INPE NIL)
    )
  ;-----------  TYPE 1  ------------------
    (IF (AND (> DSS R0F) (< DEE R0F))
     (ENTMOD (SUBST (CONS 50 ANGPS) (ASSOC 50 FIGG) FIGG))
    )

    (IF (AND (= DSS R0F) (< DEE R0F) ) (PROGN
     (IF (/= ANGPE NIL)
      (ENTMOD (SUBST (CONS 50 ANGPE) (ASSOC 50 FIGG) FIGG))
     )
     (IF (AND (=  ANGPE NIL) (>= ANGPA ANGSS) (<= ANGPA ANGEE))
      (ENTMOD (SUBST (CONS 50 ANGPS) (ASSOC 50 FIGG) FIGG))
     )
    ))

    (IF (AND (< DSS R0F) (< DEE R0F) (<= ANGPA ANGEE) (>= ANGPA ANGSS)) (PROGN
     (COMMAND "LAYER" "S"  (CDR (ASSOC 8 FIGG)) "")
     (COMMAND "ERASE" PN "")
     (COMMAND "ARC"  "C" CIP1  INPE  PEE )
     (COMMAND "ARC"  "C" CIP1  PSS   INPS)
    ))
  ;-----------  TYPE 2  ------------------
    (IF (AND (> DSS R0F) (= DEE R0F)) (PROGN
     (SETQ ANGPA (ATOF (RTOS (ANGLE CIP1 (POLAR CIP1 (ANGLE CIP1 CIP0) R1))
                             2 5)))
     (IF (AND (> ANGEE (DTR 360)) (>= ANGEO ANGPA) (>= ANGPA (DTR 0)) )
      (SETQ ANGPA (ATOF (RTOS (+ ANGPA (DTR 360)) 2 5)))
     )
     (IF (AND (>= ANGPA ANGSS) (<= ANGPA ANGEE))
      (ENTMOD (SUBST (CONS 50 ANGPS) (ASSOC 50 FIGG) FIGG))
      (COMMAND "ERASE" PN "")
     )
    ))

    (IF (AND (= DSS R0F) (= DEE R0F) (>= ANGPA ANGSS) (<= ANGPA ANGEE) )
     (COMMAND "ERASE" PN "")
    )

    (IF (AND (< DSS R0F) (= DEE R0F) (>= ANGPA ANGSS) (<= ANGPA ANGEE) )
     (ENTMOD (SUBST (CONS 51 ANGPS) (ASSOC 51 FIGG) FIGG))
    )
  ;-----------  TYPE 3  ------------------
    (IF (AND (> DSS R0F) (> DEE R0F) )  (PROGN
     (IF (AND (= ANGPS NIL) (= ANGPE NIL)) (COMMAND "ERASE"  PN ""))
     (IF (AND (/= INPS NIL) (/= INPE NIL))  (PROGN
      (SETQ PN  (SUBST (CONS 50 ANGPS) (ASSOC 50 FIGG) FIGG))
      (SETQ PN  (SUBST (CONS 51 ANGPE) (ASSOC 51 FIGG) PN))
      (ENTMOD PN)
     ))
    ))

    (IF (AND (= DSS R0F) (> DEE R0F))  (PROGN
     (SETQ ANGPA (ANGLE CIP1 (POLAR CIP1 (ANGLE CIP1 CIP0) R1)))
     (IF (AND (> ANGEE (DTR 360)) (>= ANGEO ANGPA) (>= ANGPA (DTR 0)) )
      (SETQ ANGPA (ATOF (RTOS(+ ANGPA (DTR 360)) 2 5)))
     )
     (IF (AND (>= ANGPA ANGSS) (<= ANGPA ANGEE))
      (PROGN
       (IF (=  ANGPE NIL) (ENTMOD (SUBST (CONS 51 ANGPS) (ASSOC 51 FIGG) FIGG)))
       (IF (/= ANGPE NIL) (ENTMOD (SUBST (CONS 51 ANGPE) (ASSOC 51 FIGG) FIGG)))
      )
       (COMMAND "ERASE" PN "")
     )
    ))

    (IF (AND (< DSS R0F) (> DEE R0F))
     (ENTMOD (SUBST (CONS 51 ANGPS) (ASSOC 51 FIGG) FIGG))
    )
  ) ;ENDDEFUN OF DA9ARCALFA
