pedrocg1 Posted October 30, 2020 Posted October 30, 2020 Hello all! I wonder if there's any known LISP able to replace all blocks in a drawing which fulfill a certain wildcard by another specific block. I have many many blocks containing the word "SM_Annotation" (SM_Annotation_161784, SM_Annotation_898437 and so on) and they have unsignificant differences between them. It would be nice if I were able to replace them all by a simple block I did myself. (The origin will be maintained, it will all work fine as long as I can just replace them all) Those blocks are inside other blocks (They aren't nested inside themselves, but they are inside blocks overall) Any idea, or possible solution, thanks a bunch! Quote
Lee Mac Posted October 31, 2020 Posted October 31, 2020 (edited) Assuming that the blocks are not attributed or dynamic, then the following should work: (defun c:test ( / doc new pat ) (setq pat (strcase "*SM_Annotation*") new (strcase "SM_Annotation") doc (vla-get-activedocument (vlax-get-acad-object)) ) (vlax-for blk (vla-get-blocks doc) (if (and (= :vlax-false (vla-get-isxref blk)) (/= new (strcase (vla-get-name blk))) ) (vlax-for obj blk (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (wcmatch (strcase (vla-get-name obj)) pat) ) (vla-put-name obj new) ) ) ) ) (vla-regen doc acallviewports) (princ) ) (vl-load-com) (princ) Edited October 31, 2020 by Lee Mac 1 Quote
pedrocg1 Posted November 5, 2020 Author Posted November 5, 2020 On 10/31/2020 at 7:25 PM, Lee Mac said: Assuming that the blocks are not attributed or dynamic, then the following should work: (defun c:test ( / doc new pat ) (setq pat (strcase "*SM_Annotation*") new (strcase "SM_Annotation") doc (vla-get-activedocument (vlax-get-acad-object)) ) (vlax-for blk (vla-get-blocks doc) (if (and (= :vlax-false (vla-get-isxref blk)) (/= new (strcase (vla-get-name blk))) ) (vlax-for obj blk (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (wcmatch (strcase (vla-get-name obj)) pat) ) (vla-put-name obj new) ) ) ) ) (vla-regen doc acallviewports) (princ) ) (vl-load-com) (princ) Worked perfectly!! Thanks a bunch Two issues though: - It would be nice if I could prompt the user to enter the string used upon calling the function. (It would correspond to both the wildcard and the name of the block to substitute the others) - It seems to not work whenever there's a special character in the string.. There's a group of blocks named "SM_início paginação" (name is in portuguese) with which I'd like to do the same process and the LISP doesn't seem to read those Thank you! Quote
BIGAL Posted November 5, 2020 Posted November 5, 2020 The answer to user input is straight forward, (setq pat (strcase (getstring "\nEnter wild card block name ")) new (strcase (getstring "\nEnter new block name ")) re portuguese not sure hopefully Lee can help. Quote
Recommended Posts
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.