Happy Monday,
I've been twigging around with a selectionset, but no luck. I need to build a ss with several named blocks and a few dynamic blocks which get selected as anonymous. Unfortunately not all dynamic blocks should be selected and I can find no way of either filtering out a list of dynamic blocks to exclude nor any way to campare to a list of dynamic blocks that I want selected. Below is the best idea that I had but if I wrap it into a foreach with an exclusion list, I get an empty selection set returned. (I'm guessing that I need to trim the pairs each iteration and only return the matches instead.) Admittedly I'm confused
(SETQ blklst (LIST "Cleaner" "DRAIN" "Return" "Therapy" "PoolLight" "Paraleveler" "Waterleveler" "Skimmer" "UMSLEEVE") blst "Cleaner,DRAIN,Return,Therapy,PoolLight,Paraleveler,Waterleveler,Skimmer,UMSLEEVE" ) (IF (AND (SETQ ss (SSGET "x" (LIST '(0 . "INSERT") (CONS 2 (STRCAT "`*U*" blst)) '(410 . "Model")))) (FOREACH i blklst (MAPCAR '(LAMBDA (x) (IF (NOT (EQ i (VLA-GET-EFFECTIVENAME (VLAX-ENAME->VLA-OBJECT (CADR x))))) (SSDEL (CADR x) ss) ) ) (SSNAMEX ss) ) ) ) (WHILE (SETQ Ent (SSNAME ss 0)) (SETQ BlkName (CDR (ASSOC 2 (ENTGET Ent)))) (IF (SETQ tempList (ASSOC BlkName EndList)) (SETQ EndList (SUBST (CONS BlkName (1+ (CDR tempList))) tempList EndList)) (SETQ EndList (CONS (CONS BlkName 1) EndList)) ) (SSDEL Ent ss) ) )
The other code is long and I'd rather not confuse things; if I do not try to filter out any Unames, then everything works great and fast. Once I add in the "foreach i blklst" the code breaks and I get:
; error: null interface pointer: #<VLA-OBJECT 0000000000000000>
returned.
Any suggestions are greatly appreciated. Thank you in advance.
Solved! Go to Solution.
Solved by phanaem. Go to Solution.
Hi mid-awe
In any case, your mapcar function delete entities from selection set because it checks the block name against EVERY item in blklst. One of them may be the same, but not the others.
Another thing, you have 3 loops: foreach, mapcar (which processes every element whitin list) and while.
You can group all these actions into a single loop.
Try this (limited tested)
(setq blklst (list "Cleaner" "DRAIN" "Return" "Therapy" "PoolLight" "Paraleveler" "Waterleveler" "Skimmer" "UMSLEEVE") blst (apply 'strcat (mapcar '(lambda (b) (strcat "," (strcase b))) blklst)) ) (if (setq ss (ssget "X" (list '(0 . "insert") (cons 2 (strcat "`*U*" blst)) '(410 . "model")))) (repeat (setq i (sslength ss)) (setq object (vlax-ename->vla-object (ssname ss (setq i (1- i)))) blkname (vlax-get object (if (vlax-property-available-p object 'EffectiveName) 'EffectiveName 'Name)) ) (if (wcmatch (strcase blkname) blst) (if (setq templist (assoc blkname endlist)) (setq endlist (subst (cons blkname (1+ (cdr templist))) templist endlist)) (setq endlist (cons (cons blkname 1) endlist)) ) ) ) )
@mid-awe wrote:
The only remaining issue is that it no longer recognizes multiple instances of the same dynamic block with differing visibility states.
I didn't see anything regarding visibility states in your code.
This snippet will create a selection set ss1 which contain all blocks that match block name list.
(setq blklst (list "HEA" "SEGR" "Cleaner" "DRAIN" "Return" "Therapy" "PoolLight" "Paraleveler" "Waterleveler" "Skimmer" "UMSLEEVE") blst (apply 'strcat (mapcar '(lambda (b) (strcat "," (strcase b))) blklst)) ) (if (setq ss1 (ssadd) ss (ssget "X" (list '(0 . "insert") (cons 2 (strcat "`*U*" blst)) '(410 . "model")))) (repeat (setq i (sslength ss)) (setq object (vlax-ename->vla-object (setq e (ssname ss (setq i (1- i))))) blkname (vlax-get object (if (vlax-property-available-p object 'EffectiveName) 'EffectiveName 'Name)) ) (if (wcmatch (strcase blkname) blst) (ssadd e ss1) ) ) )
This article explores another method to tackle this problem from the opposite direction, that is, constructing a selection set of only the required anonymous block references, rather than removing the superfluous references from the set retrieved.
You would need to write another function based on the method for it to be efficient for more than one block name, but some food for thought perhaps.
Lee
Can't find what you're looking for? Ask the community or share your knowledge.