Raise all height blocks at the same time LSP

Raise all height blocks at the same time LSP

S_v_d_Markt
Contributor Contributor
574 Views
7 Replies
Message 1 of 8

Raise all height blocks at the same time LSP

S_v_d_Markt
Contributor
Contributor

Hi,

For a project i'm currently on I have to raise the plan by 0.05m.

More often than not this happens and it takes way to long to do this by hand.

Does anyone know of a lisp add a given value to the attributes?

We use blocks as elevation markers and all attributes have the same name.

I'm open to changing the way we use these if that's necessary. 

s_van_der_markt_0-1689169088117.png

s_van_der_markt_1-1689169432776.png

 

It's my first post on this forum so if I did anything wrong please do tell.

 

0 Likes
Accepted solutions (1)
575 Views
7 Replies
Replies (7)
Message 2 of 8

GeeHaa
Collaborator
Collaborator

Hi,

You might not need a Lisp Routine to do this. You could just click on one of the Blocks then right click and hit select similar. Then type properties on the command line and change the z for all of them at once.

0 Likes
Message 3 of 8

S_v_d_Markt
Contributor
Contributor

Hi,

I'm afraid I do because they've all got differing values.

I don't know if it matters but I'm not trying to change the Z value but an attribute within the block which would represent the Z value. We draw completely flat, without elevation or Z values

0 Likes
Message 4 of 8

Moshe-A
Mentor
Mentor
Accepted solution

@S_v_d_Markt  hi,

 

check INCNUM command 😀

 

warrning

if the block has more than 1 numeric attribute, it will also increment also

 

 

enjoy

Moshe

 

 

(vl-load-com)

(defun c:incnum (/ askreal is_pure_num formatStr ; local functions
		   savDimzin def inc ename AcDbBlkRef AcDbAttrib val)

 (defun askreal (def / ask)
  (if (not (setq ask (getreal (strcat "\nIncrement value <" (rtos def 2 2) ">: "))))
   (setq ask def)
   (setq def ask)
  )
 ); askreal

 ; anonymous function 
 (setq is_pure_num (lambda (s) (vl-every (function (lambda (n) (or (member n '(37 43 45 46 80 112)) (and (>= n 48) (<= n 57))))) (vl-string->list s))))

 (defun formatStr (n)
  (cond
   ((= n 0.0)
    (strcat "%%p0.00")
   )
   ((< n 0.0)
    (rtos n 2 2)
   )    
   (t
    (strcat "+" (rtos n 2 2))
   )
  ); cond
 ); formatStr
  
 ; here start c:incnum 
 (setvar "cmdecho" 0)
 (command ".undo" "_begin")
  
 (setq savDimzin (getvar "dimzin"))
 (setvar "dimzin" 0)
  
 (if (= (getvar "userr2") 0.0)
  (setq def (setvar "userr2" 5.0))
  (setq def (getvar "userr2"))
 )
  
 (if (and
       (setvar "userr2" (setq inc (askreal def)))
       (setq ss (ssget '((0 . "insert") (66 . 1))))
     )
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (setq AcDbBlkRef (vlax-ename->vla-object ename))

   (foreach AcDbAttrib (vlax-invoke AcDbBlkRef 'GetAttributes)
    (if (is_pure_num (setq val (vla-get-textString AcDbAttrib)))
     (vla-put-textString AcDbAttrib (formatStr (+ (atof val) inc)))
    )
    (vlax-release-object AcDbAttrib) 
   ); foreach

   (vlax-release-object AcDbBlkRef)
  ); foreach
 ); if

 (setvar "dimzin" savDimzin)
  
 (command ".undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
); c:incnum

 

 

0 Likes
Message 5 of 8

S_v_d_Markt
Contributor
Contributor
Thank you so much this is exactly what I needed. After testing it works perfectly!
0 Likes
Message 6 of 8

Moshe-A
Mentor
Mentor

Great,

 

Make sure the block does not cotain more attributes and if it does, it's value should be a string not pure number.

 

Moshe

 

 

 

0 Likes
Message 7 of 8

S_v_d_Markt
Contributor
Contributor
Yeah I tested it with both blocks, and it works perfectly fine. The HK0565 value always has a letter as the first value so it didn't react. Which is great. Thanks again
0 Likes
Message 8 of 8

Moshe-A
Mentor
Mentor

And thats gives you the option to use this lisp in any elevation block with any attribute tag name - all goes 🤣

 

Beautiful lisp Ha?!

 

 

0 Likes