Message 1 of 9
add auto prifix to many text
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Taking what you have excellent code by Lee added the do_prifix0 also its probably better to change the defun names so no conflict with original code.
;; (pstext "Prefix Text" "Suffix Text" <mode>)
;;
;; <mode> = 0 - single selection
;; = 1 - window selection
;;
;; Author: Lee Mac 2011 - www.lee-mac.com
;; Suffix changed to increment number by AlanH June 2021
(defun pstext ( preftext sufftext mode / a e i s )
(cond
( (= 0 mode)
(while
(progn (setvar 'ERRNO 0) (setq e (car (nentsel)))
(cond
( (= 7 (getvar 'ERRNO))
(princ "\nMissed, try again.")
)
( (eq 'ENAME (type e))
(if (wcmatch (cdr (assoc 0 (entget e))) "TEXT,MTEXT,ATTRIB")
(progn
(entmod
(setq e (entget e)
a (assoc 1 e)
e (subst (cons 1 (strcat preftext (cdr a) (rtos sufftext 2 0))) a e)
)
)
(setq sufftext (+ sufftext 1))
)
(princ "\nInvalid Object.")
)
)
)
)
)
)
( (setq s (ssget "_:L" (list '(0 . "TEXT,MTEXT"))))
(repeat (setq i (sslength s))
(entmod
(setq e (entget (ssname s (setq i (1- i))))
a (assoc 1 e)
e (subst (cons 1 (strcat preftext (cdr a) (rtos sufftext 2 0))) a e)
)
)
(setq sufftext (+ sufftext 1))
)
)
)
(princ)
)
(defun c:do_prifx1 ( )
(setq h101 (getstring "\nPrefix "))
(setq h102 (getint "\nSub number "))
(pstext h101 h102 1)
)
(defun c:do_prifx0 ( )
(setq h101 (getstring "\nPrefix "))
(setq h102 (getint "\nSub number "))
(pstext h101 h102 1)
)
@the_ameral wrote:
I ALREADY SEARCHED ABOUT IT AND FOUND SMOE LISPS DO PRIFIX TO txt but not autonumber
;; (pstext "Prefix Text" "Suffix Text" <mode>)
;;
;; <mode> = 0 - single selection
;; = 1 - window selection
;;
;; Author: Lee Mac 2011 - www.lee-mac.com
(defun pstext (preftext sn mode / a e i s)
(cond
((= 0 mode)
(while
(progn
(setvar 'ERRNO 0)
(setq e (car (nentsel)))
(cond
((= 7 (getvar 'ERRNO))
(princ "\nMissed, try again.")
)
((eq 'ENAME (type e))
(if
(wcmatch (cdr (assoc 0 (entget e))) "TEXT,MTEXT,ATTRIB")
(progn
(entmod
(setq e (entget e)
a (assoc 1 e)
e (subst (cons 1
(strcat preftext (autolabel:padzeros (itoa sn) 3)
(cdr a)))
a
e
)
)
)
(setq sn (1+ sn))
)
(princ "\nInvalid Object.")
)
)
)
)
)
)
((setq s (ssget "_:L" (list '(0 . "TEXT,MTEXT"))))
(repeat (setq i (sslength s))
(entmod
(setq e (entget (ssname s (setq i (1- i))))
a (assoc 1 e)
e (subst (cons 1 (strcat preftext (autolabel:padzeros (itoa sn) 3)
(cdr a))) a e)
)
)
(setq sn (1+ sn))
)
)
)
(princ)
)
(defun c:do_prifxINC ()
(if
(and
(setq h101 (getstring "\nPrefix "))
(setq startnumber (getint "\nStarting number: "))
)
(pstext h101 startnumber 1)
)
)
(defun autolabel:padzeros (str len)
(if (< (strlen str) len)
(autolabel:padzeros (strcat "0" str ) len)
(strcat str "-")
)
)
HTH
EDIT: Oops, @Sea-Haven beat me to it.