leonucadomi Posted April 11 Posted April 11 hello all: some routine to number like this... 1.-Select a source text with numeric data. example "002" 2.- Then select the texts one by one and number them, giving them the consecutive number to the original value. 3.-Modified texts will always have 3 digits at the end. example: 001 , 034, 100.... Quote
BIGAL Posted April 12 Posted April 12 You have many posts so you should know by now all the functions required, so have a go. pick text then atoi (while pick text next number check is 2 or 3 digits <10 <100 so pad with "0" update text entmod or vlax-put 'textstring ) end while 1 Quote
Steven P Posted April 12 Posted April 12 I did this using Lee Macs Copy Swap Text LISP as a basis, adding in the increment portion as required. Quote
GLAVCVS Posted April 13 Posted April 13 (edited) Why not something different...? ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** (defun c:txtIncrem (/ tam capa ind para a txsel lstent le l s dameTexto errores error0) (defun errores (mens) (setq *error* error0) (prin1) ) (defun dameTexto (/ tx) ;;; WRITE HERE THE CODE YOU NEED TO CUSTOMIZE THE TEXT YOU WANT TO ENTER OR CREATE (cond ((= (strlen (setq tx (itoa (setq ind (+ ind 1))))) 1) (strcat "00" tx) ) ((= (strlen tx) 2) (strcat "0" tx) ) (T tx) ) ) (while (not para) (if (setq ent (car (entsel "\nSelect index text..."))) (if (= (cdr (assoc 0 (setq lstent (entget ent)))) "TEXT") (if (wcmatch (setq ind (cdr (assoc 1 lstent))) "#,##,###,####") (setq ind (atoi ind) capa (cdr (assoc 8 lstent)) a (cdr (assoc 40 lstent)) para T) (princ "\n*** The selected object is not valid. Please, try again... ***") ) ) (setq para T) ) ) (setq error0 *error* *error* errores ) (setq tam (* (getvar "pickbox") (/ (GETVAR "VIEWSIZE") (CADR (GETVAR "SCREENSIZE")))) para nil) (princ "\nSelect text to modify or insert new text (RIGHT CLICK for exit)...") (while (and (setq l (grread T (if s 4 13) (if s 2 0))) (member (car l) '(5 3))) (if (setq s (ssget "_C" (list (- (car (setq p (cadr l))) tam) (- (cadr p) tam)) (list (+ (car p) tam) (+ (cadr p) tam)) (list (cons 0 "TEXT")) ) ) (cond ((= (car l) 3) (entmod (subst (cons 1 (dameTexto)) (assoc 1 (setq le (entget (ssname s 0)))) le)) ) ;Here are other possible cases ) (cond ((= (car l) 3) (entmake (list '(0 . "TEXT") (cons 8 capa) (cons 40 a) (cons 1 (dameTexto)) (cons 10 (list (car p) (cadr p) 0.0)) ) ) ) ;Here are other possible cases ) ) ) (princ) ) Edited April 13 by GLAVCVS 2 1 Quote
GLAVCVS Posted April 13 Posted April 13 Simply: insert new text or modify existing text based on the cursor position. Quote
GLAVCVS Posted April 13 Posted April 13 Note: I have only included "TEXT" objects in the code consideration. 1 Quote
PGia Posted April 13 Posted April 13 On 4/13/2025 at 2:10 PM, GLAVCVS said: Why not something different...? ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** (defun c:txtIncrem (/ tam capa ind para a txsel lstent le l s dameTexto errores error0) (defun errores (mens) (setq *error* error0) (prin1) ) (defun dameTexto (/ tx) ;;; WRITE HERE THE CODE YOU NEED TO CUSTOMIZE THE TEXT YOU WANT TO ENTER OR CREATE (cond ((= (strlen (setq tx (itoa (setq ind (+ ind 1))))) 1) (strcat "00" tx) ) ((= (strlen tx) 2) (strcat "0" tx) ) (T tx) ) ) (while (not para) (if (setq ent (car (entsel "\nSelect index text..."))) (if (= (cdr (assoc 0 (setq lstent (entget ent)))) "TEXT") (if (wcmatch (setq ind (cdr (assoc 1 lstent))) "#,##,###,####") (setq ind (atoi ind) capa (cdr (assoc 8 lstent)) a (cdr (assoc 40 lstent)) para T) (princ "\n*** The selected object is not valid. Please, try again... ***") ) ) (setq para T) ) ) (setq error0 *error* *error* errores ) (setq tam (* (getvar "pickbox") (/ (GETVAR "VIEWSIZE") (CADR (GETVAR "SCREENSIZE")))) para nil) (princ "\nSelect text to modify or insert new text (RIGHT CLICK for exit)...") (while (and (setq l (grread T (if s 4 13) (if s 2 0))) (member (car l) '(5 3))) (if (setq s (ssget "_C" (list (- (car (setq p (cadr l))) tam) (- (cadr p) tam)) (list (+ (car p) tam) (+ (cadr p) tam)) (list (cons 0 "TEXT")) ) ) (cond ((= (car l) 3) (entmod (subst (cons 1 (dameTexto)) (assoc 1 (setq le (entget (ssname s 0)))) le)) ) ;Here are other possible cases ) (cond ((= (car l) 3) (entmake (list '(0 . "TEXT") (cons 8 capa) (cons 40 a) (cons 1 (dameTexto)) (cons 10 (list (car p) (cadr p) 0.0)) ) ) ) ;Here are other possible cases ) ) ) (princ) ) Expand Disruptive and useful Quote
Nikon Posted April 14 Posted April 14 On 4/13/2025 at 2:10 PM, GLAVCVS said: (if (setq ent (car (entsel "\nSelect index text..."))) Expand I'm trying to change the text index query, but the code doesn't work correctly after the changes., is there a way to fix this? (setq ind (atoi (getstring "\nEnter starting index text: "))) Quote
Steven P Posted April 14 Posted April 14 Tip: use getint instead of getstring (for integers) or getreal for real numbers 1 Quote
GLAVCVS Posted April 14 Posted April 14 On 4/14/2025 at 11:12 AM, Nikon said: I'm trying to change the text index query, but the code doesn't work correctly after the changes., is there a way to fix this? (setq ind (atoi (getstring "\nEnter starting index text: "))) Expand As StevenP says, to request any parameter from the keyboard, consider the following: -If it's an integer: 'getint' -If it's a decimal number: 'getreal' -If it's a text string: 'getstring' The advantage of using 'getint' or 'getreal' (as appropriate) is that the function itself will prevent the user from entering data that doesn't match the expected type. However, if you use 'getstring', any data entered will be considered a text string and will need to be converted. In this case, if the user had mistakenly entered a string beginning with a non-numeric character (for example, "y734"), converting it with 'atoi' or 'atof' would return 0. Therefore, it's advisable to use the 'get...' functions appropriately. 1 1 Quote
Nikon Posted April 14 Posted April 14 (edited) On 4/14/2025 at 11:28 AM, Steven P said: Tip: use getint instead of getstring (for integers) or getreal for real numbers Expand After Enter index text, there is a possibility modify existing text based on the cursor position, but it doesn't work for inserting new text. ; a bad attempt at code modification ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** (defun c:txtIncrem (/ tam capa ind para a txsel lstent le l s dameTexto errores error0) (defun errores (mens) (setq *error* error0) (prin1) ) (defun dameTexto (/ tx) (cond ((= (strlen (setq tx (itoa (setq ind (+ ind 1))))) 1) tx) ((= (strlen tx) 2) tx) (T tx)) ) (setq ind (getint "\nEnter index text: ")) ;; ??? (setq error0 *error* *error* errores) (setq tam (* (getvar "pickbox") (/ (GETVAR "VIEWSIZE") (CADR (GETVAR "SCREENSIZE")))) para nil) (princ "\nSelect text to modify or insert new text (RIGHT CLICK for exit)...") (while (and (setq l (grread T (if s 4 13) (if s 2 0))) (member (car l) '(5 3))) (if (setq s (ssget "_C" (list (- (car (setq p (cadr l))) tam) (- (cadr p) tam)) (list (+ (car p) tam) (+ (cadr p) tam)) (list (cons 0 "TEXT")) )) (cond ((= (car l) 3) (entmod (subst (cons 1 (dameTexto)) (assoc 1 (setq le (entget (ssname s 0)))) le)) ) ) (cond ((= (car l) 3) (entmake (list '(0 . "TEXT") (cons 8 capa) (cons 40 a) (cons 1 (dameTexto)) (cons 10 (list (car p) (cadr p) 0.0)) )) ) ) ) ) (princ) ) Edited April 14 by Nikon 1 Quote
GLAVCVS Posted April 14 Posted April 14 (edited) On 4/14/2025 at 11:50 AM, Nikon said: After Enter index text, there is a possibility modify existing text based on the cursor position, but it doesn't work for inserting new text. ; a bad attempt at code modification ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** (defun c:txtIncrem (/ tam capa ind para a txsel lstent le l s dameTexto errores error0) (defun errores (mens) (setq *error* error0) (prin1) ) (defun dameTexto (/ tx) (cond ((= (strlen (setq tx (itoa (setq ind (+ ind 1))))) 1) tx) ((= (strlen tx) 2) tx) (T tx)) ) (setq ind (getint "\nEnter index text: ")) ;; ??? (setq error0 *error* *error* errores) (setq tam (* (getvar "pickbox") (/ (GETVAR "VIEWSIZE") (CADR (GETVAR "SCREENSIZE")))) para nil) (princ "\nSelect text to modify or insert new text (RIGHT CLICK for exit)...") (while (and (setq l (grread T (if s 4 13) (if s 2 0))) (member (car l) '(5 3))) (if (setq s (ssget "_C" (list (- (car (setq p (cadr l))) tam) (- (cadr p) tam)) (list (+ (car p) tam) (+ (cadr p) tam)) (list (cons 0 "TEXT")) )) (cond ((= (car l) 3) (entmod (subst (cons 1 (dameTexto)) (assoc 1 (setq le (entget (ssname s 0)))) le)) ) ) (cond ((= (car l) 3) (entmake (list '(0 . "TEXT") (cons 8 capa) (cons 40 a) (cons 1 (dameTexto)) (cons 10 (list (car p) (cadr p) 0.0)) )) ) ) ) ) (princ) ) Expand Ok. Edited April 14 by GLAVCVS Quote
GLAVCVS Posted April 14 Posted April 14 Sorry, I think I responded too quickly in my previous comment. Your suggestion is correct. Quote
GLAVCVS Posted April 14 Posted April 14 Sorry. I hadn't noticed enough. Something happens if you disable the code for selecting the sample text: the variables 'capa and 'a' are left undefined. You should assign them a value somehow. Quote
Nikon Posted April 14 Posted April 14 (edited) On 4/14/2025 at 12:08 PM, GLAVCVS said: Something happens if you disable the code for selecting the sample text: the variables 'capa and 'a' are left undefined. You should assign them a value somehow. Expand Is it possible to leave the default values as in the source code? Edited April 14 by Nikon Quote
GLAVCVS Posted April 14 Posted April 14 On 4/14/2025 at 12:15 PM, Nikon said: Is it possible to leave the default values as in the source code? Expand Of course. You can use the current layer, for example. You could write: (if (not layer) (setq layer (getvar "CLAYER"))) (if (not a) (setq a (getint "\nHeight for texts: "))) Quote
Nikon Posted April 14 Posted April 14 On 4/14/2025 at 12:39 PM, GLAVCVS said: (if (not layer) (setq layer (getvar "CLAYER"))) (if (not a) (setq a (getint "\nHeight for texts: "))) Expand In your source code, for example, when I change the text selection to a text query, the text is not inserted. Quote
GLAVCVS Posted April 14 Posted April 14 Another important thing to note: you must enter the value of 'a' by pressing ENTER, not RIGHT CLICK, so that the code can enter the GRREAD loop. Otherwise, you would have to add 12 to the '(5 3)' list, but the '...(RIGHT CLICK for exit)...' function would be disabled. GRREAD is like this 1 Quote
GLAVCVS Posted April 14 Posted April 14 (edited) Also: I suggested you enter the height with 'getint'. I think it's better to use 'getreal' so you can enter decimals if necessary. So, maybe you should change it. Edited April 14 by GLAVCVS 1 Quote
PGia Posted April 17 Posted April 17 Hi @GLAVCVS On 4/13/2025 at 2:10 PM, GLAVCVS said: Why not something different...? ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** (defun c:txtIncrem (/ tam capa ind para a txsel lstent le l s dameTexto errores error0) (defun errores (mens) (setq *error* error0) (prin1) ) (defun dameTexto (/ tx) ;;; WRITE HERE THE CODE YOU NEED TO CUSTOMIZE THE TEXT YOU WANT TO ENTER OR CREATE (cond ((= (strlen (setq tx (itoa (setq ind (+ ind 1))))) 1) (strcat "00" tx) ) ((= (strlen tx) 2) (strcat "0" tx) ) (T tx) ) ) (while (not para) (if (setq ent (car (entsel "\nSelect index text..."))) (if (= (cdr (assoc 0 (setq lstent (entget ent)))) "TEXT") (if (wcmatch (setq ind (cdr (assoc 1 lstent))) "#,##,###,####") (setq ind (atoi ind) capa (cdr (assoc 8 lstent)) a (cdr (assoc 40 lstent)) para T) (princ "\n*** The selected object is not valid. Please, try again... ***") ) ) (setq para T) ) ) (setq error0 *error* *error* errores ) (setq tam (* (getvar "pickbox") (/ (GETVAR "VIEWSIZE") (CADR (GETVAR "SCREENSIZE")))) para nil) (princ "\nSelect text to modify or insert new text (RIGHT CLICK for exit)...") (while (and (setq l (grread T (if s 4 13) (if s 2 0))) (member (car l) '(5 3))) (if (setq s (ssget "_C" (list (- (car (setq p (cadr l))) tam) (- (cadr p) tam)) (list (+ (car p) tam) (+ (cadr p) tam)) (list (cons 0 "TEXT")) ) ) (cond ((= (car l) 3) (entmod (subst (cons 1 (dameTexto)) (assoc 1 (setq le (entget (ssname s 0)))) le)) ) ;Here are other possible cases ) (cond ((= (car l) 3) (entmake (list '(0 . "TEXT") (cons 8 capa) (cons 40 a) (cons 1 (dameTexto)) (cons 10 (list (car p) (cadr p) 0.0)) ) ) ) ;Here are other possible cases ) ) ) (princ) ) Expand I'm testing your code. But when I zoom in/out during the command, the switch from crosshair to pickbox doesn't work as expected. Is there a way to fix this? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.