Jump to content

Recommended Posts

Posted
17 hours ago, BIGAL said:

 

This post is like option 2 of this post. Is there an option 3 ? Will answer last question in other post. Suggest keep all in one post.

 

Give this a try does both requests.

(defun c:addval ( / lst lst2 att cnt lst3)
(setq inc (getreal "\nEnter increment + or - "))
(setq ss (ssget '((0 . "TEXT,ATTDEF"))))
(setq lst '() tnum 0 tatt 0)
(repeat (setq x (sslength ss))
 (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
 (setq objname (vlax-get obj 'objectname))
 (if (= objname "AcDbText")
  (progn 
   (vlax-put obj 'textstring (rtos (+  (atof (vlax-get obj 'textstring)) inc) 2 0))
   (setq tnum (1+ tnum))
  )
  (progn
   (vlax-put obj 'tagstring (rtos (+  (atof (vlax-get obj 'tagstring)) inc) 2 0))
   (setq tatt (1+ tatt))
  )
 )
)
(alert (strcat (rtos tnum 2 0) " text changed \n" (rtos tatt 2 0) " tags Changed"))
(princ)
)

If you introduce more objects may need a cond rather than using IF.

This tool is great but I need the numbering to be in this format 001, 050....I mean that a zero accompanies the number

 la numeracion que aqui manejamos usa 3 digitos

 

Posted
17 hours ago, BIGAL said:

 

This post is like option 2 of this post. Is there an option 3 ? Will answer last question in other post. Suggest keep all in one post.

 

Give this a try does both requests.

(defun c:addval ( / lst lst2 att cnt lst3)
(setq inc (getreal "\nEnter increment + or - "))
(setq ss (ssget '((0 . "TEXT,ATTDEF"))))
(setq lst '() tnum 0 tatt 0)
(repeat (setq x (sslength ss))
 (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
 (setq objname (vlax-get obj 'objectname))
 (if (= objname "AcDbText")
  (progn 
   (vlax-put obj 'textstring (rtos (+  (atof (vlax-get obj 'textstring)) inc) 2 0))
   (setq tnum (1+ tnum))
  )
  (progn
   (vlax-put obj 'tagstring (rtos (+  (atof (vlax-get obj 'tagstring)) inc) 2 0))
   (setq tatt (1+ tatt))
  )
 )
)
(alert (strcat (rtos tnum 2 0) " text changed \n" (rtos tatt 2 0) " tags Changed"))
(princ)
)

If you introduce more objects may need a cond rather than using IF.

You can add something like this to make the numbering 3 digits?

 

like this

 

(setq i 1
)
   (foreach sub lst
      (setq lent (entget (last sub))
            txt (strcat (if (< i 10) "00" (if (< i 100) "0" "")) (itoa i))
            i (1+ i)
      )
      (entmod (subst (cons 1 txt)(assoc 1 lent) lent))
   )

 

 

Posted

Another go.

(defun c:addval ( / lst lst2 att cnt lst3)
(setq inc (getreal "\nEnter increment + or - "))
(setq ss (ssget '((0 . "TEXT,ATTDEF"))))
(setq lst '() tnum 0 tatt 0)
(repeat (setq x (sslength ss))
 (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
 (setq objname (vlax-get obj 'objectname))
 (if (= objname "AcDbText")
  (progn 
  (setq newt (+  (atof (vlax-get obj 'textstring)) inc))
   (cond
   ((< newt 10 ) (setq newt (strcat "00" (rtos newt 2 0))))
   ((< newt 100) (setq newt (strcat "0" (rtos newt 2 0))))
   (setq newt (rtos newt 2 0))
   )
   (vlax-put obj 'textstring newt)
   (setq tnum (1+ tnum))
  )
  (progn
  (setq newt (+  (atof (vlax-get obj 'tagstring)) inc))
  (cond
   ((< newt 10) (setq newt (strcat "00" (rtos newt 2 0))))
   ((< newt 100) (setq newt (strcat "0" (rtos newt 2 0))))
   (setq newt (rtos newt 2 0))
  )
  (vlax-put obj 'tagstring newt)
  (setq tatt (1+ tatt))
  )
 )
)
(alert (strcat (rtos tnum 2 0) " text changed \n" (rtos tatt 2 0) " tags Changed"))
(princ)
)

 

  • Thanks 1
Posted
8 hours ago, BIGAL said:

Another go.

(defun c:addval ( / lst lst2 att cnt lst3)
(setq inc (getreal "\nEnter increment + or - "))
(setq ss (ssget '((0 . "TEXT,ATTDEF"))))
(setq lst '() tnum 0 tatt 0)
(repeat (setq x (sslength ss))
 (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
 (setq objname (vlax-get obj 'objectname))
 (if (= objname "AcDbText")
  (progn 
  (setq newt (+  (atof (vlax-get obj 'textstring)) inc))
   (cond
   ((< newt 10 ) (setq newt (strcat "00" (rtos newt 2 0))))
   ((< newt 100) (setq newt (strcat "0" (rtos newt 2 0))))
   (setq newt (rtos newt 2 0))
   )
   (vlax-put obj 'textstring newt)
   (setq tnum (1+ tnum))
  )
  (progn
  (setq newt (+  (atof (vlax-get obj 'tagstring)) inc))
  (cond
   ((< newt 10) (setq newt (strcat "00" (rtos newt 2 0))))
   ((< newt 100) (setq newt (strcat "0" (rtos newt 2 0))))
   (setq newt (rtos newt 2 0))
  )
  (vlax-put obj 'tagstring newt)
  (setq tatt (1+ tatt))
  )
 )
)
(alert (strcat (rtos tnum 2 0) " text changed \n" (rtos tatt 2 0) " tags Changed"))
(princ)
)

 

 

EXCELLENT MASTER :) , THANK YOU

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