Hi folks,
I am trying to select a specific block and delete it with Lisp.
I can not pick the block using any selection mode. Reason being is I want to run a batch script on several files.
For instance, I have this code which will work, however, if If place the code in a loop to delete all REVISION_SYMBOL_I_22x34 blocks in a drawing, it will actually delete all unamed blocks and not just the one I need deleted. It seems that my code just selectes any unamed block after it deletes the first one I want when I place in a loop (loop no in code below). Any help appreciated. Thanks
Moderator edit: Put code in code window, use </> button.
(defun c:DeleteBlocks ()
(vl-load-com)
(setq blockName "REVISION_SYMBOL_I_22x34")
(setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blockName)))))
(setq blkRef (ssname ss 0))
(vla-delete (vlax-ename->vla-object blkRef))
(ssdel blkRef ss)
(princ)
)
Solved! Go to Solution.
Solved by azmand01!e. Go to Solution.
Solved by paullimapa. Go to Solution.
What if you replaced this line:
(strcat "`*U*," blockName)
with this:
blockName
Maybe you missed something
That line of code should now look like this
(setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blockName))))
I had an extra parentheses..
Correct to this.. but this won't find the block or any other block.
Moderator edit: please post code to code window using </> button.
(defun c:DelRevBlk ()
(vl-load-com)
(setq blockName "REVISION_SYMBOL_I_22x34")
(setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blockName))))
(setq blkRef (ssname ss 0))
(vla-delete (vlax-ename->vla-object blkRef))
So far only this version finds the block. But it finds any block that has a uname, not specifically the one I want deleted.
(setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blockName)))))
(ssdel blkRef ss)
(princ)
)
Looks like the block you’re searching for is then a dynamic block placed in the dwg. Then use this
(setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blockName)))))
(setq blkRef (ssname ss 0))
(setq obj (vlax-ename->vla-object blkRef))
(if (eq (vla-get-effectivename obj) blockName) (ssdel blkRef ss))
But this only checks the first of the selection set. You should loop through the entire set and if it finds the matching effective block name then it’ll delete the block from the set
I needed to change this line to:
(if (and (eq (vla-get-effectivename obj) blockName)
(entdel blkRef))
and then it works .
Thanks for help.
Glad that worked out for you…cheers!!!
Can't find what you're looking for? Ask the community or share your knowledge.