Increase number inside block

Increase number inside block

andreas7ZYXQ
Advocate Advocate
1,135 Views
6 Replies
Message 1 of 7

Increase number inside block

andreas7ZYXQ
Advocate
Advocate

Im trying to develop a code that will cout increase a number inside a block/attribute.

I want to start to choose a prefix before my number. Ex. 01.xxx

Then i want to write wich number to start with after my prefix Ex. 01.001
Its important that the number have 3 digits.

After i would like to select my block, next block and so on and increase my number automatic.


Does anyone have an idea to help me. There is som issues with the code that i cant figure out on my own.

 

(defun C:adress()
(princ "\n ADRESS - Count the adress")
(setq textb (getstring T "\nText before nr: "))
(setq num (getint "\nStarting number: "))
(while (<= doing 50)
 (setq txt (strcat textb (itoa num) textb))
 (princ txt)
 (setq blk1 (car (entsel "\nChoose block:")))
    (setq ed (entget blk1))
	(if (= "ATTRIB" (cdr (assoc 0 ed)))
		(if (= blk1 (cdr (assoc 330 ed)))
			(if (= "ADR" (cdr (assoc 2 ed)))
				(entmod (subst (cons 1 txt)(assoc 1 ed)ed))
			)
		)
	) 
)
)
0 Likes
Accepted solutions (1)
1,136 Views
6 Replies
Replies (6)
Message 2 of 7

pbejse
Mentor
Mentor

Need help with your code? or are you okay with a new one? 

 

use nentselp in selecting the ATTRIBUTE on the block

 

(setq blk1 (car (nentsel "\nChoose Attribute")))
(setq ed (entget blk1))
(if (and (= "ATTRIB" (cdr (assoc 0 ed)))
     (= "ADR" (cdr (assoc 2 ed))))
              (entmod (subst (cons 1 txt)
                             (assoc 1 ed)
                             ed))
              )

 

Quick edit on your code

 

(defun C:adress  ()
      (princ "\n ADRESS - Count the adress")
      (setq textb (getstring T "\nText before nr: "))
      (setq num (getint "\nStarting number: "))
      (while (<= doing 50)
            (setq txt (strcat textb
                              "."
                              (nth (strlen (setq sn (itoa num)))
                                   '(nil "00" "0" ""))
                              sn))
            (princ txt)

            (IF (setq blk1 (car (nentsel "\nChoose block:")))
                  (progn
                        (setq ed (entget blk1))
                        (if (and (= "ATTRIB"
                                    (cdr (assoc 0 ed)))
                                 (= "ADR" (cdr (assoc 2 ed))))
                              (entmod (subst (cons 1 txt)
                                             (assoc 1 ed)
                                             ed))
                              )

(setq num (1+ num))
                                       
                        )
                  )
            )
      )

 

0 Likes
Message 3 of 7

andreas7ZYXQ
Advocate
Advocate

Thanks alot.

In my drawing i have a bunch och blocks with empty attributes. Thats why i was thinking about selecting the block since i know my attribute is always named adr.

Tried the modified code but it will not change the attribute inside the block.. Any ideas?

thanks again

0 Likes
Message 4 of 7

pbejse
Mentor
Mentor
Accepted solution

@andreas7ZYXQ wrote:

Thanks alot.

In my drawing i have a bunch och blocks with empty attributes. Thats why i was thinking about selecting the block since i know my attribute is always named adr.

Tried the modified code but it will not change the attribute inside the block.. Any ideas?

thanks again


You need to choose the ATTRIBUTE not just any part of the block, that is the way your code is setup.

 

Oops, you did say blank.. hang on. Will modify the code...

 

 

(defun C:adress  ()
      (princ "\n ADRESS - Count the adress")
      (setq textb (getstring T "\nText before nr: "))
      (setq num (getint "\nStarting number: "))

      
      (while (<= doing 50)
            (setq txt (strcat textb "."
                              (nth (strlen (setq sn (itoa num)))
                                   '(nil "00" "0" "")) sn))
            (princ txt)

            (IF (setq blk1 (car (entsel "\nChoose block:")))
                
                  (progn
                        (while (/= "SEQEND"
                                (cdr (assoc 0
                                            (setq etdata
                                                       (entget
                                                             (setq blk1 (entnext blk1)))))))
                           (and (= (cdr (assoc 0 etdata)) "ATTRIB")
                                (equal (cdr (assoc 2 etdata)) "ADR")
                                (entmod (subst (cons 1 txt)
                                               (assoc 1 etdata)
                                               etdata))))
			(setq num (1+ num))                 
                       )
                  )
            )
      )
0 Likes
Message 5 of 7

andreas7ZYXQ
Advocate
Advocate

Thanks!

You just saved my day.

0 Likes
Message 6 of 7

pbejse
Mentor
Mentor

No problem, You did most of the work andreas7ZYXQ.

 

Cheers

 

pBe

0 Likes
Message 7 of 7

Anonymous
Not applicable

Hi,

i think i need the same thing, but i don't really know what did you do. Can you please show me example of that block?

Thanks

0 Likes