;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;幕匠LISP实验室;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;程序功能：中英文等高调整软件  [备注：中英文等高调整软件(调英文)]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun *error*(st)
  (princ (strcat "Error: " st))
  (princ)
)

(defun unt(s$ old$ new$ / osl nsl si st)
  (setq osl (strlen old$)
        nsl (strlen new$)
        si 1)
  (while (= osl (strlen (setq st (substr s$ si osl))))
    (if (= st old$)
      (setq s$ (strcat (substr s$ 1 (1- si)) new$ (substr s$ (+ si osl)))
            si (+ si nsl)
      )
      (setq si (1+ si))
    )
  )
  (setq txt s$)
)

(DEFUN C:MJ141 ( / test test1 test2 ss len n s en1 a ent nn
                 txt stxt post)
  (setvar "CMDECHO" 0)
  (setq test T nn 0)
  (while test
    (setq ss (ssadd))
    (setq ss (ssget))
    (if (= nil ss)
      (setq test nil)
      (progn
	(setq len (sslength ss))
	(setq n 1 s 1)
	(while (<= n len)
	  (setq en1 (ssname ss (1- n)))
	  (setq a (entget en1))
          (if (= "TEXT" (cdr (assoc 0 a)))
	    (progn
              (setq txt (cdr (assoc 1 a)))
              (unt txt "%%165" "")
              (unt txt "%%166" "")
              (setq post 1 stxt nil txt1 "" test1 nil test2 1)
              (while (/= stxt "")
                (setq stxt (substr txt post 1))
                (if (and (<= (ascii stxt) 160) (= test2 1))
                  (progn
                    (setq txt1 (strcat txt1 "%%166"))
                    (setq test2 nil)
                    (setq test1 1)
                  )
                )
                (if (and (> (ascii stxt) 160) (= test1 1))
                  (progn
                    (setq txt1 (strcat txt1 "%%165"))
                    (setq test1 nil)
                    (setq test2 1)
                  )
                )
                (setq txt1 (strcat txt1 stxt))
                (setq post (1+ post))
              )
              (setq ent (subst (cons 1 txt1) (assoc 1 a) a))
              (entmod ent)
              (setq nn (1+ nn))
	    )
	  )
	  (setq n (1+ n))
	)
      )
    )
  )
  (princ (strcat (itoa nn) " changed !"))
  (princ)
)
