Renumber the first letter of mtexts in sequence

Renumber the first letter of mtexts in sequence

symoin
Enthusiast Enthusiast
414 Views
5 Replies
Message 1 of 6

Renumber the first letter of mtexts in sequence

symoin
Enthusiast
Enthusiast

Hi All,

I am looking for a lisp to renumber the first letter of mtexts in sequence.

I need to select the Mtexts and it should change the sl. Number or the first letter of the Mtexts in order or i will select each mtext individually and it should renumber in sequence.

Drawing atttached

0 Likes
Accepted solutions (1)
415 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

It should be fairly straight forward look for the "-" then look at what is in front of it and replace with a number, ask before selecting what is start number.

 

 

(setq pos (vl-string-position  45 str))
(setq strend (substr str (+ pos 1)))
(setq newstr (strcat (atoi num) strend))

 

Your home work is select text, strcat, then update text 2 methods entmod or Vla-put-textstring.

 

0 Likes
Message 3 of 6

symoin
Enthusiast
Enthusiast
; I TRIED TO CODE BUT THIS IS NOT WORKING.

(defun c:ren ( / ss)
(vl-load-com)
(if (and (setq ss (ssget (list (cons 0 "*text"))))
(setq pos (vl-string-position 45 str))
(setq strend (substr str (+ pos 1)))
(setq newstr (strcat (atoi num) strend))
)
(princ)
)
)
0 Likes
Message 4 of 6

komondormrex
Mentor
Mentor

hey there,

check the following

(defun c:re_index_mtext (/ index mtext_sset )
	(if (setq index 0 mtext_sset (ssget '((0 . "mtext"))))
				(foreach mtext (vl-sort (vl-remove-if 'listp (mapcar 'cadr (ssnamex mtext_sset)))
									   '(lambda (mtext_1 mtext_2) (> (caddr (assoc 10 (entget mtext_1))) (caddr (assoc 10 (entget mtext_2)))))
							   )
						 (vla-put-textstring (vlax-ename->vla-object mtext) 
						 					 (strcat (itoa (setq index (1+ index))) "-" 
											 		 (vl-string-left-trim " " (substr (vla-get-textstring (vlax-ename->vla-object mtext))
													 	     						  (+ 2 (vl-string-position (ascii "-") (vla-get-textstring (vlax-ename->vla-object mtext)))) 
																			  )
													 )
											 )
						 )
				)
	)
)
0 Likes
Message 5 of 6

symoin
Enthusiast
Enthusiast
Thanks komondor mrex
Its working good, can we have an option to ask for the first number? Please
0 Likes
Message 6 of 6

komondormrex
Mentor
Mentor
Accepted solution

sure

 

(defun c:re_index_mtext (/ start_index mtext_sset )
	(if (setq mtext_sset (ssget '((0 . "mtext"))))
		(progn
			(initget 6)
			(setq start_index (1- (getint "\nEnter starting index: "))) 
			(foreach mtext (vl-sort (vl-remove-if 'listp (mapcar 'cadr (ssnamex mtext_sset)))
								   '(lambda (mtext_1 mtext_2) (> (caddr (assoc 10 (entget mtext_1))) (caddr (assoc 10 (entget mtext_2)))))
						   )
					 (vla-put-textstring (vlax-ename->vla-object mtext) 
						 				 (strcat (itoa (setq start_index (1+ start_index))) "-" 
											 	 (vl-string-left-trim " " (substr (vla-get-textstring (vlax-ename->vla-object mtext))
													 	     					  (+ 2 (vl-string-position (ascii "-") (vla-get-textstring (vlax-ename->vla-object mtext)))) 
																		  )
												 )
										 )
					 )
			)
		)
	)
	(princ)
)

 

0 Likes