Jump to content

Recommended Posts

Posted

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

image.thumb.png.446aca5882f315f57ce1de2a57d90089.png

 

Posted

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

  • Funny 1
Posted

I did this using Lee Macs Copy Swap Text LISP as a basis, adding in the increment portion as required.

Posted (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 by GLAVCVS
  • Like 2
  • Thanks 1
Posted

Simply: insert new text or modify existing text based on the cursor position.

Posted

Note: I have only included "TEXT" objects in the code consideration.

  • Thanks 1
Posted
  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 👍

Posted
  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: ")))

Posted

Tip: use getint instead of getstring (for integers) or getreal for real numbers

  • Thanks 1
Posted
  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.

  • Like 1
  • Thanks 1
Posted (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 by Nikon
  • Thanks 1
Posted (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 by GLAVCVS
Posted

Sorry, I think I responded too quickly in my previous comment.
Your suggestion is correct.

Posted

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.

Posted (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 by Nikon
Posted
  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: "))) 

 

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

Posted

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

  • Thanks 1
Posted (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 by GLAVCVS
  • Thanks 1
Posted

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?

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...