Jump to content

Incrementing attribute values


Lee Chu Chu
 Share

Recommended Posts

There are multiple attributes that I want to be able to increment by 1. However there are a couple of problems, there are different attributes but I want to be able to select all of them and I the value that I want to increment by 1 has a letter before it.

Link to comment
Share on other sites

;; window select block with attribute which has attribute starting with a latter
;; advance it by 1

(setq *inc* 1
     i	0
)
(sssetfirst nil nil)

(defun c:incatt	(/ x ss ent i)
 (if (setq ss (ssget ":L" '((0 . "INSERT") (66 . 1))))
   (repeat (setq i (sslength ss))
     (setq ent (entget (entnext (ssname ss (setq i (1- i))))))
     (if (= (cdr (assoc 0 ent)) "ATTRIB")
(if (wcmatch (cdr (setq n (assoc 1 ent))) "@*")
  (progn
    (setq x (+ *inc* (atoi (substr (cdr (assoc 1 ent))2))))
	 (setq  x (strcat (substr (cdr n) 1 1) (itoa x)))
   



    (entmod (subst (cons 1 x) n ent))
  )
)
     )
   )
 )
)



Link to comment
Share on other sites

@ samifox

 

You have lots of things to consider in your codes .

 

1- Since that you considered a static number to add to the text string in attributes , you can replace the global variable *inc* with number 1

2- You did set the variable ( i ) with zero and reset the same variable with the number of object in the selection set , so it is useless .

3- Your codes would modify the first attribute object if it was the first object crated in the block and it has a character as a starting of the text string .

4- Finally , you need to add while function to cycle through all objects in the selection set ( Block Definitions ) .

 

Hope this help .

Link to comment
Share on other sites

That code doesn't do anything of the sort/ anything that I want it to. It just shows me the properties of all the attributes that I have selected. I tried modifying the code but to no avail.

Link to comment
Share on other sites

All I want the program to do is to select the multiple types of attributes and just increment the particular tag for the attribute called "CCTNUM" by 1. I don't want any options, just increment

Link to comment
Share on other sites

I have managed to get the code to work but it increments the attribute tag and I am unable to find the associate tag for the value I want to change.

 

4 found
((-1 . <Entity name: 7f6ce7fc8b0>) (0 . "ATTRIB") (330 . <Entity name: 7f6ce7fc8a0>) (5 . "7EB") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "ESYMB_35") (6 . "Continuous") (100 . "AcDbText") (10 -43270.9 -15513.9 0.0) (40 . 250.0) (1 . "P4") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "ISOCP") (71 . 0) (72 . 1) (11 -43078.2 -15388.9 0.0) (210 0.0 0.0 1.0) (100 . "AcDbAttribute") (280 . 0) (2 . "DB DESIGNATION") (70 . 0) (73 . 0) (74 . 2) (280 . 0))

 

This is what is outputs and it changes the (1.P4) value but theres another value for the attribute that has the value something like E1. That is the one that I want to change.

Link to comment
Share on other sites

Try this program .

 

(defun c:Test ( / ss )
 ;;;    Tharwat . 06.02.2015    ;;;
(if (setq ss (ssget "_:L" '((0 . "INSERT")(66 . 1))))
 ((lambda ( x / sn st )
    (while (setq sn (ssname ss (setq x (1+ x))))
      (vl-some '(lambda (v) (if (and (eq (strcase (vla-get-tagstring v)) "CCTNUMBERS")
                                     (wcmatch (setq st (vla-get-textstring v)) "@*#")
                                     )
                              (progn (vla-put-textstring v (strcat (substr st 1 1) (itoa (1+ (read (substr st 2)))))) t)
                              ))
               (vlax-invoke (vlax-ename->vla-object sn) 'getattributes)
               )))
   -1 )
 )
(princ)
) (vl-load-com)

Link to comment
Share on other sites

Try this program .

 

(defun c:Test ( / ss )
 ;;;    Tharwat . 06.02.2015    ;;;
(if (setq ss (ssget "_:L" '((0 . "INSERT")(66 . 1))))
 ((lambda ( x / sn st )
    (while (setq sn (ssname ss (setq x (1+ x))))
      (vl-some '(lambda (v) (if (and (eq (strcase (vla-get-tagstring v)) "CCTNUMBERS")
                                     (wcmatch (setq st (vla-get-textstring v)) "@*#")
                                     )
                              (progn (vla-put-textstring v (strcat (substr st 1 1) (itoa (1+ (read (substr st 2)))))) t)
                              ))
               (vlax-invoke (vlax-ename->vla-object sn) 'getattributes)
               )))
   -1 )
 )
(princ)
) (vl-load-com)

 

i really like your code ...so efficient!

Link to comment
Share on other sites

  • 6 years later...

I´m trying to increment the sum of attributes from one dinamic block to another dinamic block. Each block have 3 equally named attributes from A to C. Then i fill each attribute with numbers for example "A" = 1, "B"=1, "C=1 into block "1" and "A" = 2, "B"=2, "C=2 into block "2".

My goal is to select block "1" and then block "2" and add the sum directly to block "2" attributes.

Is this possible?

 

Thanks in advance!

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

 Share

×
×
  • Create New...