Jump to content

text with the same content incremental numbering


Juergen

Recommended Posts

Hi,

 

I use the search function from Acad to find all

the same text contant and write per hand then the pos at

the end of the text.

Is there a way to write it automatic?

 

Thx. for your help.

Drawing.dwg

Link to comment
Share on other sites

Try this, But This possible  only MTEXT

 

(defun c:pos  ( / tl snum svnames svvals ss sta_full num sta)
(setq svnames '(osmode cmdecho blipmode plinewid vtenable) svvals (mapcar 'getvar svnames))
(mapcar 'setvar svnames '(0 0 0 0 0))
(setq num (getdist "\n Enter Starting Number"))
(while
	(if	(setq ss (ssget ":S" '((0 . "MTEXT") )))
		(progn
			(setq tl (strlen (strcat (rtos num 2 0))))
			(if (< tl 2)
				(setq snum (strcat "0" (rtos num 2 0)))
				(setq snum (strcat (rtos num 2 0)))
			)
			(setq sta_full (cdr (assoc 1 (entget (ssname ss 0)))))
			(setq sta (strcat sta_full "\\C1" "xPos." snum))
			(mapcar '(lambda (z) (vla-put-textstring z sta)) (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
			(setq num (1+ num))
		)
	)							
)
(mapcar 'setvar svnames svvals)
)
(princ "\n| Type \"POS\" to Awake |")
(princ)

 

file here

 

Increment Text.lsp

Link to comment
Share on other sites

(setq num (getdist "\n Enter Starting Number"))

Doubtful that the number is 123.456 (getint would be better.

 

I think the answer required is more select a single text, using that as a pattern find all the matching texts and add the pos.x, then pick next text and add the pos.x+1

Link to comment
Share on other sites

Hi Kajanthan,

 

i tried to run your file, but i get the info "; Error: Bad string for ssget mode" .

The starting number should be 01.

Link to comment
Share on other sites

2 hours ago, Juergen said:

Hi Kajanthan,

 

i tried to run your file, but i get the info "; Error: Bad string for ssget mode" .

The starting number should be 01.

 

 

First you Convert TEXT To MTEXT using command "TXT2MTXT".

 

Sample4.gif.ca4eefacd4cc0c2f487d97c44bd70d84.gif

 

Without Starting Number.

 Corrected lisp

 

Increment Text.lsp

Link to comment
Share on other sites

Hi Kajanthan,

 

i change the text into mtext but

i have the same report: bad string ... ssget

 

I use a german version.

 

Any Idea?

Link to comment
Share on other sites

Give this dynamic increment a go.

(defun c:Test (/ sel lst yup)
  ;; Tharwat - Date: 20.Apr.2021	;;
  (and (or *inc_* (setq *inc_* 1))
       (setq
         *inc_* (cond ((getint (strcat "\nSpecify increment number < "
                                       (itoa *inc_*)
                                       " > : "
                               )
                       )
                      )
                      (*inc_*)
                )
       )
       (while
         (and (setq sel (car (entsel "\nSelect Mtext to add increment suffix : ")))
              (setq yup (= (cdr (assoc 0 (setq lst (entget sel)))) "MTEXT"))
              (entmod (subst (cons 1
                                   (strcat (cdr (assoc 1 lst))
                                           "{\\C1;xPos."
                                           (if (> 10 *inc_*)
                                             (strcat "0" (itoa *inc_*))
                                             (itoa *inc_*)
                                           )
                                           "}"
                                   )
                             )
                             (assoc 1 lst)
                             lst
                      )
              )
              (setq *inc_* (1+ *inc_*))
         )
       )
  )
  (and sel (not yup) (princ "\nInvalid object. Try again <!>"))
  (princ)
)

 

Link to comment
Share on other sites

hi tharwat,

 

thanks for your answer.

But what i need is all text with the same content should become the same

Pos.

 

3050x489xPos.01

3050x1250xPos.02

3050x544xPos.03

3050x1098xPos.04

3050x1250xPos.02

3050x544xPos.03

3050x489xPos.01

......and so on

 

 

Link to comment
Share on other sites

Then there is no need to convert your Texts to Mtexts, so the following should change the similar text strings automatically that reside into your current active space.

(defun c:Test (/ sel lst int ent)
  ;; Tharwat - Date: 20.Apr.2021	;;
  (and (or *inc_* (setq *inc_* 1))
       (setq
         *inc_* (cond ((getint (strcat "\nSpecify increment number < "
                                       (itoa *inc_*)
                                       " > : "
                               )
                       )
                      )
                      (*inc_*)
                )
       )
       (while
         (and (setq sel
                     (car (entsel "\nSelect Text to add increment suffix : "))
              )
              (= (cdr (assoc 0 (setq lst (entget sel)))) "TEXT")
              (setq int -1
                    sel (ssget "_X"
                               (list '(0 . "TEXT")
                                     (assoc 1 lst)
                                     (cons 410 (getvar 'CTAB))
                               )
                        )
              )
              (while (setq int (1+ int)
                           ent (ssname sel int)
                     )
                (setq lst (entget ent))
                (entmod (subst (cons 1
                                     (strcat (cdr (assoc 1 lst))
                                             "xPos."
                                             (if (> 10 *inc_*)
                                               (strcat "0" (itoa *inc_*))
                                               (itoa *inc_*)
                                             )
                                     )
                               )
                               (assoc 1 lst)
                               lst
                        )
                )
              )
              (setq *inc_* (1+ *inc_*))
         )
       )
  )
  (princ)
)

 

Edited by Tharwat
Codes added. lol
  • Like 1
Link to comment
Share on other sites

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