find replace regex and arithmetic operations

find replace regex and arithmetic operations

jtm2020hyo
Collaborator Collaborator
1,226 Views
3 Replies
Message 1 of 4

find replace regex and arithmetic operations

jtm2020hyo
Collaborator
Collaborator

I need to add +1 to the column "before" block attribute values:

example, I need convert 2149 to 2150 (2149+1)

imagen.png

 

anyone can help me with this?

 

PD: regex can be useful when I need to just find specific values.

PD2: attached dwg.

0 Likes
Accepted solutions (3)
1,227 Views
3 Replies
Replies (3)
Message 2 of 4

CodeDing
Advisor
Advisor
Accepted solution

@jtm2020hyo ,

 

Assuming you will use the same block and attribute each time, this should get the job done for you.

(defun c:P1 ( / ss len cnt e tmp badCnt)
(prompt "\nSelect Blocks for Plus 1: ")
(if (setq badCnt 0 ss (ssget '((0 . "INSERT"))))
  (progn
    (setq len (sslength ss))
    (repeat (setq cnt len)
      (setq e (ssname ss (setq cnt (1- cnt))))
      (if (and (wcmatch (getpropertyvalue e "BlockTableRecord/Name") "ALIM-TG*")
	       (numberp (read (setq tmp (getpropertyvalue e "TG")))))
        (setpropertyvalue e "TG" (itoa (1+ (atoi tmp))))
      ;else
	(setq badCnt (1+ badCnt))
);if );repeat (prompt (strcat "\nSuccessfully added one to " (itoa (- len badCnt)) " of " (itoa len) " blocks.")) );progn ;else (prompt "\n...no blocks selected.") );if (setq ss nil) (princ) );defun

Best,

~DD

Message 3 of 4

Sea-Haven
Mentor
Mentor
Accepted solution

If your block only has 1 attribute then a simpler way is to use the attribute order, when you do a foreach att obviously the 1st is the one and only attribute so change the value, this way block name is not required.

 

So you can make a defun that passes the attribute position as a more global use. 

 

(defun c:P1 (num  /

(setq x 1)
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS K )) 'getattributes)
	(if (= x num)
	(vla-put-textstring att newstring)
	)
      (setq x (+ x 1))
)

(c:p1 2)
Message 4 of 4

devitg
Advisor
Advisor
Accepted solution

Also you can do ATTOUT , open the TXT file , change att as need. save as TXT , and ATTIN.