Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Edit and replace dynamic block attributes

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
orourkestuart
458 Views, 4 Replies

Edit and replace dynamic block attributes

I'm looking for a simple LISP to change the attribute entries in an existing dynamic block.

 

I have a block "DIAG_CROSS" that has up to 14 attributes. I need to change 2 of the attributes in specific ways.

 

1: The attribute "SIZE" needs to be changed from a real number to an integer and then rewritten to the block attribute as e.g. 50.000 becomes 50. I understand the rtoi operator, but I don't know how to write the result back to the block.

 

2: The attribute "CODE" needs to have any numerical characters removed from the end and then rewritten back to the block attribute as e.g. WUG13 becomes WUG. I understand the VL-STRING-RIGHT-TRIM "0123456789" operation but don't know how to write the result back to the block.

 

 

thanks in advance

 

 

 

4 REPLIES 4
Message 2 of 5
ВeekeeCZ
in reply to: orourkestuart

Possibly like this.

Untested. Since you did not bother with posting a sample block, the test and fix is up to you.

 

(vl-load-com)

(defun c:DiagCrossTrim ( / s i e n z c)
  
  (if (setq s (ssget '((0 . "INSERT"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (if (and (not (vl-catch-all-error-p (setq n (vl-catch-all-apply 'getpropertyvalue (list e "BlockTableRecord/Name")))))
	       (= n "DIAG_CROSS")
	       (not (vl-catch-all-error-p (setq z (vl-catch-all-apply 'getpropertyvalue (list e "SIZE")))))
	       (not (vl-catch-all-error-p (setq c (vl-catch-all-apply 'getpropertyvalue (list e "CODE")))))
	       )
	(progn
	  (setpropertyvalue e "SIZE" (itoa (fix (atof z))))
	  (setpropertyvalue e "CODE" (vl-string-right-trim "0123456789" c))))))
  (princ)
  )

 

Message 3 of 5
orourkestuart
in reply to: ВeekeeCZ

thanks for that. will test it now

Message 4 of 5

On first testing it mostly works, it does prompt me to "select objects" but I can fix that. I actually didn't realise that rtoi isn't a thing in LISP until I started trying to resolve it myself. I also hadn't encountered getpropertyvalue and setpropertyvalue before. cheers for this BeeKeeCZ 🙂

Message 5 of 5
ВeekeeCZ
in reply to: orourkestuart

I guess it could be shortened by a bit using just

(itoa (atoi z))

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report