Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I could not make it with Text count command so can anyone find a solution for this.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
s_manoosmanoos
469 Views, 6 Replies

I could not make it with Text count command so can anyone find a solution for this.

Dears,

 

I have attached a drawing which is not able to create sequential numbers using tcount command.

i need to mention the sequential number in the 3rd draw as "modified". is it possible?

Labels (2)
6 REPLIES 6
Message 2 of 7
Sea-Haven
in reply to: s_manoosmanoos

I would look at a custom lisp get a string and change last character, re the 001, you can do this by taking into account the number in a cond and convert to a string.

 

Try this the 12 & 13 were not in correct order if I select all in one go. A pick pick works fine.

(defun c:wow ( / )
(setq str (getstring "\nEnter character to look for "))
(setq numasc (ascii str))
(setq num (getint "\nEnter start number "))
(setq ss (ssget '((0 . "*Text"))))
(if (= ss nil)
(alert "No text selected ")
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq str (vlax-get obj 'textstring))
(setq pos (vl-string-position numasc str))
(setq strst (substr str 1 pos))
(setq strend (substr str (+ pos 2)))
(cond 
((< num 10)(setq str (strcat strst "00" (rtos num 2 0) strend)))
((< num 100)(setq str (strcat strst "0" (rtos num 2 0) strend)))
((> num 99)(setq str (strcat strst (rtos num 2 0) strend)))
)
(vlax-put obj 'textstring str)
(setq num (1+ num))
)
)
(princ)
)
(c:wow)

 

Message 3 of 7
john.uhden
in reply to: Sea-Haven

@Sea-Haven ,

I see what you mean.  If the convention should always be from left to right, then rather than pick pick pick how about sorting the objects from left to right before processing?

John F. Uhden

Message 4 of 7

The same questions which is raised by Mr @john.uhden,I wanted to ask to Mr @Sea-Haven

How can we sort it out?😇

Message 5 of 7
john.uhden
in reply to: s_manoosmanoos

I'm sure @Sea-Haven knows how to do the sorting...

Convert the selection set to a list like '((ename x)(ename x) etc.) and sort the list from lowest X to highest X, then process the sorted list.

John F. Uhden

Message 6 of 7

hey,

check the following

 

 

(defun c:replace_@_x_lr_number (/ m_text_sset m_text_start_index total_digits step)
	(sssetfirst)
	(if (and 
			(sssetfirst nil (ssget '((0 . "*text"))))
			(setq m_text_sset (ssget "_i" '((1 . "*`@*"))))
			(null (sssetfirst))
		)
		(progn
			(setq m_text_start_index 1
				  total_digits "000"
				  step 1
			)
			(mapcar '(lambda (m_text)
						(progn
							(vla-put-textstring m_text
												(vl-string-subst (strcat (substr total_digits 
																				 1 
																				 (- (strlen total_digits) 
																				 	(strlen (itoa m_text_start_index))
																				 )
																		 ) 
																		 (itoa m_text_start_index)
																 )
																 "@"
																 (vla-get-textstring m_text)
												)
							)
							(setq m_text_start_index (+ step m_text_start_index))
						)
					 )
					 (vl-sort (mapcar 'vlax-ename->vla-object 
									(vl-remove-if 'listp (mapcar 'cadr (ssnamex m_text_sset)))
							  )
							 '(lambda (m_text_1 m_text_2)
							  	(< (car (vlax-get m_text_1 'insertionpoint)) (car (vlax-get m_text_2 'insertionpoint)))
							  )
					 )
			)

		)
		(sssetfirst)
	)
	(princ)
)

 

 

Message 7 of 7
Sea-Haven
in reply to: s_manoosmanoos

As John suggested there is another way to select and make sure of labelling in a user order, and that is to use SSGET "F" then compare a intersection point distance. 

 

 

; By AlanH Sept 2023
; update a character in a string to an increasing number

(defun c:wow ( / )
(setq str (getstring "\nEnter character to look for "))
(setq numasc (ascii str))

(setq num (getint "\nEnter start number "))

(setq pt1 (getpoint "\nPick 1st drag point ") pt2 (getpoint pt1 "\nPick 2nd point "))
(setq ang (angle pt1 pt2))
(setq pt3 (polar pt2 (+ ang (/ pi 2.)) 1.))
(setq pt4 (polar pt1 (+ ang (/ pi 2.)) 1.))
(setq ss (ssget "CP" (list pt1 pt2 pt3 pt4 pt1) '((0 . "*Text"))))

(if (= ss nil)
 (alert "No text selected ")
  (progn
   (setq lst '())
   (repeat (setq x (sslength ss))
    (setq ent (ssname ss (setq x (- x 1))))
    (setq obj (vlax-ename->vla-object ent))
    (setq inspt (vlax-get obj 'insertionpoint))
    (setq dist (distance pt1 inspt))
    (setq lst (cons (list dist obj) lst))
   )
   (setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))
   (foreach val lst
    (setq str (vlax-get (cadr val) 'textstring))
    (setq pos (vl-string-position numasc str))
    (setq strst (substr str 1 pos))
    (setq strend (substr str (+ pos 2)))
    (cond 
     ((< num 10)(setq str (strcat strst "00" (rtos num 2 0) strend)))
     ((< num 100)(setq str (strcat strst "0" (rtos num 2 0) strend)))
     ((> num 99)(setq str (strcat strst (rtos num 2 0) strend)))
    )
   (vlax-put (cadr val) 'textstring str)
   (setq num (1+ num))
   )
  )
)
(princ)
)

(c:wow)

 

 

I used "CP" as found odd occasions missed some text.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report