Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SSGET with additional filter?

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
mid-awe
1241 Views, 7 Replies

SSGET with additional filter?

 

Happy Monday, Smiley Indifferent

 

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 Smiley Frustrated

 

(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.

7 REPLIES 7
Message 2 of 8
phanaem
in reply to: mid-awe

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))
        )
      )
    )
  )

 

Message 3 of 8
mid-awe
in reply to: phanaem

Thank you phanaem, I'll give it a run first thing in the morning.
Message 4 of 8
mid-awe
in reply to: phanaem

Thank you. The only remaining issue is that it no longer recognizes multiple instances of the same dynamic block with differing visibility states. I'll have to discover how to fix that. The intention is that only dynamic blocks matching accepted effective names remain in the list but not thrown out just because the effective names match. (if that makes any sense?)
Message 5 of 8
phanaem
in reply to: mid-awe


@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)
      )
    )
  )

 

 

 

Message 6 of 8
Lee_Mac
in reply to: mid-awe

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

Message 7 of 8
mid-awe
in reply to: phanaem

Thank you phanaem,

That seems to have it. I had to keep my original while loop to build the endlist, but after that it seems to be doing what I needed it to do. All those loops leave me a little loopy (wires crossed and all). 🙂

Again, thank you.
Message 8 of 8
mid-awe
in reply to: Lee_Mac

Thank you Lee, I'll read it through.

I'm still making use of your (LM:blk->vis uname) function later in this application, it's just that I realized after everything looked good that I had no way to filter out the other dynamic blocks so even if they didn't apply to my blocktable in this instance, they were in there anyway. at least now I have a working example.

Before phanaem spoke up, I was thinking of comparing the (member effectivename blklst). I don't know if it would've worked. Maybe another day.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost