Fett2oo5 Posted October 21, 2014 Posted October 21, 2014 (edited) Hello, I am in search for a means to select all blocks on a drawing given a wildcard. The particular wildcard we would be using is *- Dy I have been searching for a while now, and have seen suggestions of: Qselect, which has to be done from a dialog box, and doesn't allow the use of wildcards. Filter, doesn't seem to fit my needs because the names of the blocks don't seem to be available, only the AutoCAD name assignments ( I don't know what these are called but it labels blocks like this: U41, U42, U43, etc.) Is it possible to have a LISP select all blocks by a wildcard in the name? I am not that well versed in LISP routines, my only experience is with the beginner tutorials. Any help on this is greatly appreciated. Edited October 21, 2014 by Fett2oo5 LeeMac is awesome Quote
Lee Mac Posted October 21, 2014 Posted October 21, 2014 Qselect, which has to be done from a dialog box, and doesn't allow the use of wildcards. Actually QSELECT does allow wilcards if you select 'Wildcard Match' from the 'Operator' drop-down; however, QSELECT doesn't work with dynamic block names, since the command doesn't account for anonymous dynamic block references. When the dynamic properties of a dynamic block are changed, AutoCAD will automatically generate a new anonymous block definition for the block reference, which is then linked to the original dynamic block definition. Such anonymous block definitions have names *U###, as you have witnessed. For your task, I would therefore suggest the following code: (defun c:bsel ( / i p s ) (setq p "*- Dy" ;; Block name pattern p (strcase p) ) (if (setq s (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," p))))) (repeat (setq i (sslength s)) (if (not (wcmatch (strcase (LM:blockname (vlax-ename->vla-object (ssname s (setq i (1- i)))))) p)) (ssdel (ssname s i) s) ) ) ) (sssetfirst nil s) (princ) ) ;; Block Name - Lee Mac ;; Returns the true (effective) name of a supplied block reference (defun LM:blockname ( obj ) (if (vlax-property-available-p obj 'effectivename) (defun LM:blockname ( obj ) (vla-get-effectivename obj)) (defun LM:blockname ( obj ) (vla-get-name obj)) ) (LM:blockname obj) ) (vl-load-com) (princ) Quote
Fett2oo5 Posted October 21, 2014 Author Posted October 21, 2014 Lee... You are amazing. The ease and clarity you bring to Lisp and VBA writing is astonishing. Thank you very much for helping me. Each time I see one of your examples, or full projects, I learn a great deal. Thank you for being such a major contributor to the CAD and programming community. Quote
Lee Mac Posted October 21, 2014 Posted October 21, 2014 Thank you very much for your compliments & gratitude Fett2oo5 - I'm delighted to hear that my examples & contributions are beneficial to your learning. Lee Quote
MarkytheSparky Posted April 1, 2016 Posted April 1, 2016 Lee, with just minor modifications, it seems like this routine would also be able to find all blocks that begin with P302 > and explode them. is it a matter of changing the ssdel to ssexp and (setq p "P320*" ;; Block name pattern ? Quote
Lee Mac Posted April 1, 2016 Posted April 1, 2016 You can change the block name pattern to "P32*", but there is no such function as 'ssexp' - you will instead need to either use the ActiveX explode method, or call the EXPLODE command. Quote
MarkytheSparky Posted April 1, 2016 Posted April 1, 2016 (edited) Lee, so I would replace (ssdel (ssname s i) s) to something like (setq ent (ssname s i) ) (command "_explode" ent) on second thought I probably do not need the extra step of setting up a variable ent to then explode. (command "_explode"(ssname s i) s) > Edited April 1, 2016 by MarkytheSparky on second thought... Quote
MarkytheSparky Posted April 1, 2016 Posted April 1, 2016 not so lucky... (command "_explode"(ssname s i) s) can you help a brother out please? Quote
Lee Mac Posted April 1, 2016 Posted April 1, 2016 Note that the repeat loop is preparing the selection set to remove anonymous dynamic block references which do not meet the block name criteria, the final (sssetfirst) expression is then highlighting the resulting selection set. Therefore, you can call the EXPLODE command with this resulting set: (defun c:bsel ( / i p q s ) (setq p "*- Dy" ;; Block name pattern p (strcase p) ) (if (setq s (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," p))))) (repeat (setq i (sslength s)) (if (not (wcmatch (strcase (LM:blockname (vlax-ename->vla-object (ssname s (setq i (1- i)))))) p)) (ssdel (ssname s i) s) ) ) ) (if (and s (< 0 (sslength s))) (progn (setq q (getvar 'qaflags)) (setvar 'qaflags 1) (command "_.explode" s "") (setvar 'qaflags q) ) ) (princ) ) ;; Block Name - Lee Mac ;; Returns the true (effective) name of a supplied block reference (defun LM:blockname ( obj ) (if (vlax-property-available-p obj 'effectivename) (defun LM:blockname ( obj ) (vla-get-effectivename obj)) (defun LM:blockname ( obj ) (vla-get-name obj)) ) (LM:blockname obj) ) (vl-load-com) (princ) Note that QAFLAGS must be modified to allow the EXPLODE command to accept a selection set in AutoLISP. The above is untested. Quote
MarkytheSparky Posted April 1, 2016 Posted April 1, 2016 sooooo close, but no BOOM I have three blocks that show up when I invoke the command RENAME A320_05_ARCH-PP131 A320_05_ARCH-PQQ132 A320_05_ARCH-PA133 anything after the A320 is a wildcard after running the LISP I can still see the block names. Quote
MarkytheSparky Posted April 1, 2016 Posted April 1, 2016 My Bad. NooB mistake. Purge All blocks are gone. > Quote
MarkytheSparky Posted April 1, 2016 Posted April 1, 2016 Heck - now that I'm excited about this... You could probably use the same code (slightly modified) to rename some blocks... like my titleblocks 13203-TACO-22x34 - 05 - Final Assembly Line-1999464-ARCH THIRD FLOOR - AREA 1 rename to 13203-TACO-22x34_005_Border man - I could automate that step too... save my hands form carpal tunnel. Thank you so far Lee Mac. Quote
halam Posted April 1, 2016 Posted April 1, 2016 These number come from Revit export! Am I correct MarkytheSparky? This is just what I was looking for also! Great contributions for CAD management! Thanks Lee Mac Quote
MarkytheSparky Posted April 1, 2016 Posted April 1, 2016 Darn it... I have managed to explode all the blocks that begin with A320, but now I have a bunch of blocks on LAYER 0 that need to be exploded. This is a second step! Block name does not matter - but they all are on layer 0 Quote
Lee Mac Posted April 1, 2016 Posted April 1, 2016 Sounds like you two need to hire a programmer Quote
MarkytheSparky Posted April 1, 2016 Posted April 1, 2016 could you send me a bill? Make the memo out to Noob Training Quote
mikitari Posted September 25, 2017 Posted September 25, 2017 Dear Lee, BSEL works on all database, great. I have tried to modify it to crossing window selection, I have tried to replace (ssget "_X") with (ssget "_+.:E:S") and then (ssget "_:E:S") and then (ssget "_:E") and I have no luck :-( neither one gave me the chanc. What do I do wrong? Best regards! 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.