Bumping attribute values in blocks

Bumping attribute values in blocks

Dcadorette
Participant Participant
988 Views
16 Replies
Message 1 of 17

Bumping attribute values in blocks

Dcadorette
Participant
Participant

Anyone know any lisp for bumping up or down an attribute's value in blocks?

For example lets say I have 10 blocks that has an attribute that's an address set to 01:01.001 thru 01:01.010. After these 10 blocks are 10 more blocks are are set to 01:01.030 thru 01:01.040. I'm looking for something that in this circumstance would allow me to select the block that's at 01:01.030 and take that and every block who's number is higher either down or up by 'X' amount.

0 Likes
Accepted solutions (1)
989 Views
16 Replies
Replies (16)
Message 2 of 17

john.uhden
Mentor
Mentor

@Dcadorette 

Well, the numbers aren't 'REALs.  They look more like an IP address.  Breaking down the address into 3 components, to/from which component do you wish to add/subtract X?

What if the subtraction results in a negative?  Would it be 01.01.-YY or 01.00.YY?

And are there any specific tags to which this adjustment should apply, or do we go by any value matching "##.##.###?"

John F. Uhden

0 Likes
Message 3 of 17

Sea-Haven
Mentor
Mentor

Post a sample dwg.

0 Likes
Message 4 of 17

Dcadorette
Participant
Participant
Added
0 Likes
Message 5 of 17

Dcadorette
Participant
Participant

The change in number would take place in the just last 3 digits and it wouldn't go below 0 in use but if it was for some reason the it would be 01.01.-YY. Any value matching XX:XX.XXX

0 Likes
Message 6 of 17

devitg
Advisor
Advisor

@Dcadorette , nothing is added.

0 Likes
Message 7 of 17

Dcadorette
Participant
Participant
I edited it into the original post, I see it and can download it from there.
0 Likes
Message 8 of 17

devitg
Advisor
Advisor

@Dcadorette , ok. Thanks

 

0 Likes
Message 9 of 17

Sea-Haven
Mentor
Mentor
Accepted solution

Try this

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bumping-attribute-values-in-blocks/td-p/10850217

; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma 32 is space 58 colon
(defun _csv->lst ( strtxt / pos )
	(if (setq pos (vl-string-position 46 strtxt))
		(cons (substr strtxt 1 pos) (_csv->lst (substr strtxt (+ pos 2))))
		(list strtxt)
    )
)

(defun c:wow ( / ss ans txtlook txtchg obj atts attval txt val2 tstr)

(setq ss (ssget (list (cons 0 "INSERT")(cons 2 "FA_INIT_SMOKE"))))
(if (= ss nil)
(alert "no blocks found with that name")
(progn

  (if (not AH:getvalsm)(load "Multi Getvals.lsp"))
  (setq ans (AH:getvalsm (list "Enter values" "Value to look for" 5 4 "10" "Add value +/-ve " 5 4 "10")))
  (setq txtlook (- (atoi (nth 0 ans)) 1) txtchg (atoi (nth 1 ans)))

  (repeat (setq x (sslength ss))
    (setq ent (ssname ss (setq x (- x 1))))
    (setq obj (vlax-ename->vla-object ent ))
    (setq atts (vlax-invoke obj "getattributes"))
    (setq attval (vla-get-textstring (nth 0 atts)))
    (setq txt (_csv->lst attval))
    (setq val2 (atoi (cadr txt)))
    (princ val2)
    (if (> val2 txtlook)
      (progn
      (setq tstr (+ val2 txtchg))
      (cond
        ((< tstr 10)(vla-put-textstring (nth 0 atts) (strcat (car txt) ".00" (rtos tstr 2 0))))
        ((< tstr 100)(vla-put-textstring (nth 0 atts) (strcat (car txt) ".0" (rtos tstr 2 0))))
      )
    )
  )
  )
)
)

(princ)
)

SeaHaven_0-1641115384873.png

 

 

 

0 Likes
Message 10 of 17

Dcadorette
Participant
Participant

I've tried it with the value to look for at 30, 030 and .030 and the add value at 10, +10 and -10 and get this same no function definition error with each. Am I missing something?

unknown.png

Dcadorette_0-1641222644135.png

0 Likes
Message 11 of 17

devitg
Advisor
Advisor

 

 

 

 

 

0 Likes
Message 12 of 17

Dcadorette
Participant
Participant
Sorry, I'm not entirely sure what that means or is asking for
0 Likes
Message 13 of 17

devitg
Advisor
Advisor

@Dcadorette 

My fault, I erased my message , it was wrong. 

 

0 Likes
Message 14 of 17

Sea-Haven
Mentor
Mentor

It is not finding the Lee-mac function that is the error message, did you save all the code including the function.

(defun _csv->lst

 

0 Likes
Message 15 of 17

Dcadorette
Participant
Participant
works perfectly now thank you, much appreciated. If i wanted to add other block names to this would I go about it by just adding additional (cons X "Block_Name") increasing the X value?
0 Likes
Message 16 of 17

Dcadorette
Participant
Participant

@Sea-Haven  
Also I've noticed it doesn't work on triple digits and wont bump numbers above 99

0 Likes
Message 17 of 17

Sea-Haven
Mentor
Mentor
Will have a look should work for any number.
0 Likes