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
Solved! Go to Solution.
Solved by ВeekeeCZ. Go to Solution.
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) )
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 🙂
Can't find what you're looking for? Ask the community or share your knowledge.