(DEFUN C:CIRDIM1()
(SETQ LP (GETVAR "LUPREC"))
(COMMAND "SELECT" "AU" "\\")
(SETQ SA (SSGET "P" ))
(SETQ N (SSLENGTH SA))
(SETQ TC (GETVAR "TEXTSIZE"))
(SETQ SC (GETVAR "DIMLFAC"))
(SETQ I 0)
(SETQ R1 0)
(SETQ N1 0)
(SETQ TABLE '())
(SETQ TSORT '())
(REPEAT N
  (SETQ NA (ENTGET (SSNAME SA I)))
  (SETQ I (+ 1 I))
  (SETQ NB (ASSOC 0 NA))
  (IF (= "CIRCLE" (CDR NB))
      (PROGN
          (SETQ NP1 (ASSOC 40 NA))
          (SETQ R (CDR NP1))
          (SETQ R (LIST R 0))
          (SETQ TP (APPLY 'MAX R))
          (SETQ TABLE (SUBST 0 TP R))
          (SETQ TSORT (CONS TP TSORT))
          (SETQ N1 (+ N1 1))
       )
 )
)
(SETQ TABLE TSORT)
(SETQ CSORT '())
 (REPEAT (LENGTH TABLE)
    (SETQ TP (APPLY 'MAX TABLE))
    (SETQ TABLE (SUBST 0 TP TABLE))
    (SETQ CSORT (CONS TP CSORT))
 )
(PRIN1 CSORT)
(SETQ TSORT (REVERSE CSORT))
;(IF (> (CAR TSORT) (CADR TSORT))
;    (PROGN
;      (SETQ TSORT (REVERSE TSORT))
;      (SETQ TEST 3)
;    )
;)
(SETQ DP (OSNAP (GETPOINT"\nDIMENSON FROM:") "NEAR"))
(SETQ TP (GETPOINT DP "\nDIMENSON TO  :"))
(SETQ AG1 (ANGLE DP TP))
(SETQ AG2 (* PI 0.5))
(SETQ AG3 (RTD AG1))
(COMMAND "DIM" "LEADER" "NEAR" DP TP "" " " "EXIT")
;(COMMAND "LINE" DP TP "")
(PROMPT "\n")
(SETQ J N1)
(REPEAT N1
 (SETQ ST (NTH (- J 1) TSORT))
 (SETQ J (- J 1))
 (IF (/= J N1)
   (PROGN
     (IF (AND (>= AG3 0) (<= AG3 90))
         (PROGN
           (COMMAND "LINE" (POLAR TP AG1 (* -1 J TC 1.7)) (POLAR (POLAR TP AG1 (* -1 J TC 1.7)) 0 TC) "")
           (SETQ TXP (POLAR (POLAR TP AG1 (- (* -1 J TC 1.7) (* TC 0.5))) 0 (* TC  1.8)))
           (COMMAND "TEXT" TXP "" "" (STRCAT "R" (RTOS (* ST SC) 2 LP)))
         )
     )
     (IF (AND (>= AG3 270) (<= AG3 360))
         (PROGN
           (COMMAND "LINE" (POLAR TP AG1 (* -1 J TC 1.7)) (POLAR (POLAR TP AG1 (* -1 J TC 1.7)) 0 TC) "")
           (SETQ TXP (POLAR (POLAR TP AG1 (+ (* -1 J TC 1.7) (* TC 0.5))) 0 (* TC 1.4)))
           (COMMAND "TEXT" TXP "" "" (STRCAT "R" (RTOS (* ST SC) 2 LP)))
         )
     )
     (IF (AND (>= AG3 90) (<= AG3 180))
         (PROGN
           (SETQ L1 (POLAR TP AG1 (* -1 J TC 1.7)))
           (SETQ L2 (LIST (- (CAR L1) (* TC 1)) (CADR L1)))
           (COMMAND "LINE" L1 L2 "")
           (SETQ TXP (LIST (- (CAR L2) (* TC 0.5)) (- (CADR L2) (* TC 0.5))))
           (COMMAND "TEXT" "R" TXP "" "" (STRCAT "R" (RTOS (* ST SC) 2 LP)))
         )
     )
     (IF (AND (>= AG3 180) (<= AG3 270))
         (PROGN
           (SETQ L1 (POLAR TP AG1 (* -1 J TC 1.7)))
           (SETQ L2 (LIST (- (CAR L1) (* TC 1)) (CADR L1)))
           (COMMAND "LINE" L1 L2 "")
           (SETQ TXP (LIST (- (CAR L2) (* TC 0.5)) (- (CADR L2) (* TC 0.5))))
           (COMMAND "TEXT" "R" TXP "" "" (STRCAT "R" (RTOS (* ST SC)  2 LP)))
         )
     )
   )
 )
 (PRIN1 ST)
 (PROMPT "\n")
)
)
