문자 또는 숫자 자동 증가

출처 : http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getstring-if-ascii-if-integer/td-p/4397555

 

 

(defun c:tag ( / fun ins ocs str uxa )
    (while
        (not
            (or (= "" (setq str (getstring "\nSpecify grid line tag: ")))
                (wcmatch str "~*[~0-9]*")
                (wcmatch str "~*[~a-zA-Z]*")
            )
        )
        (princ "\n  숫자 또는 알파벳문자이어야 함...")
    )
    (if (/= "" str)
        (progn
            (if (wcmatch str "~*[~0-9]*")
                (setq fun (lambda ( x ) (itoa (1+ (atoi x)))))
                (setq fun LM:A++)
            )
            (setq ocs (trans '(0.0 0.0 1.0) 1 0 t)
                  uxa (angle '(0.0 0.0 0.0) (trans (getvar 'ucsxdir) 0 ocs t))
            )
            (while (setq ins (getpoint "\nSpecify point : "))
                (entmake
                    (list
                       '(00 . "TEXT")
                       '(72 . 4)
                       '(73 . 0)
                        (cons 001 str)
                        (cons 050 uxa)
                        (cons 007 (getvar 'textstyle))
                        (cons 040 (getvar 'textsize))
                        (cons 010 (trans ins 1 ocs))
                        (cons 011 (trans ins 1 ocs))
                        (cons 210 ocs)
                    )
                )
                (setq str (fun str))
            )
        )
    )
    (princ)
)

 

 

;; Alpha++  -  Lee Mac
;; Increments an alphabetical string by one, e.g. AZ => BA
;; a - [str] alphabetical string
(defun LM:A++ ( a )
    (   (lambda ( f ) (vl-list->string (reverse (f (reverse (vl-string->list a)) t))))
        (lambda ( l x )
            (cond
                (   (null l) (if x '(65) '(97)))
                (   (= 090 (car l)) (cons 65 (f (cdr l)  t )))
                (   (= 122 (car l)) (cons 97 (f (cdr l) nil)))
                (   (cons (1+ (car l)) (cdr l)))
            )
        )
    )
)
(princ)

 

'CAD > Lisp' 카테고리의 다른 글

mapcar 의 활용예 - 문자남기고 삭제  (0) 2015.02.12
치수관련 변수 목록  (0) 2015.01.03
grread 옵션 정리  (0) 2014.11.10
SSGET 사용법 정리  (0) 2014.11.07
리스트에서 순서 뽑기 기초  (0) 2014.10.27