add auto prifix to many text

add auto prifix to many text

the_ameral
Advocate Advocate
686 Views
8 Replies
Message 1 of 9

add auto prifix to many text

the_ameral
Advocate
Advocate

SDF.PNG

0 Likes
687 Views
8 Replies
Replies (8)
Message 2 of 9

ronjonp
Mentor
Mentor

Do a simple search, this problem has been solved many times over.

0 Likes
Message 3 of 9

the_ameral
Advocate
Advocate
I ALREADY SEARCHED ABOUT IT AND FOUND SMOE LISPS DO PRIFIX TO txt but not autonumber
0 Likes
Message 4 of 9

ronjonp
Mentor
Mentor

Post a solution you found that is close and I'll help you modify it to increment.

0 Likes
Message 5 of 9

the_ameral
Advocate
Advocate
;; (pstext "Prefix Text" "Suffix Text" <mode>)
;;
;; <mode> = 0 - single selection
;; = 1 - window selection
;;
;; Author: Lee Mac 2011 - www.lee-mac.com

(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")
(entmod
(setq e (entget e)
a (assoc 1 e)
e (subst (cons 1 (strcat preftext (cdr a) sufftext)) a e)
)
)
(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) sufftext)) a e)
)
)
)
)
)
(princ)
)
(defun c:do_prifx ( )
(setq h101 (getstring "\nprfix "))
(setq h102 (getstring "\nsubix "))

(pstext h101 h102 1)
)
0 Likes
Message 6 of 9

3wood
Advisor
Advisor

You can try ALTEXT.

Add prefix first, then select "previous" and renumber them automatically.

0 Likes
Message 7 of 9

Sea-Haven
Mentor
Mentor

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)
)

 

0 Likes
Message 8 of 9

pbejse
Mentor
Mentor

@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.

 

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

Pbe must have pasted at same time, for me would make a bit smarter search for last number etc.

0 Likes