Visual LISP, AutoLISP and General Customization

Reply
Mentor
mid-awe
Posts: 1,199
Registered: ‎12-08-2004
Message 1 of 8 (372 Views)
Accepted Solution

SSGET with additional filter?

372 Views, 7 Replies
01-06-2014 03:26 PM

 

Happy Monday, :smileyindifferent:

 

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 :smileyfrustrated:

 

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

Distinguished Contributor
phanaem
Posts: 149
Registered: ‎02-06-2007
Message 2 of 8 (350 Views)

Re: SSGET with additional filter?

01-06-2014 05:33 PM 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))
        )
      )
    )
  )

 

Mentor
mid-awe
Posts: 1,199
Registered: ‎12-08-2004
Message 3 of 8 (336 Views)

Re: SSGET with additional filter?

01-06-2014 07:50 PM in reply to: phanaem
Thank you phanaem, I'll give it a run first thing in the morning.
Mentor
mid-awe
Posts: 1,199
Registered: ‎12-08-2004
Message 4 of 8 (311 Views)

Re: SSGET with additional filter?

01-07-2014 08:45 AM 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?)
Distinguished Contributor
phanaem
Posts: 149
Registered: ‎02-06-2007
Message 5 of 8 (289 Views)

Re: SSGET with additional filter?

01-07-2014 01:08 PM 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)
      )
    )
  )

 

 

 

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 6 of 8 (283 Views)

Re: SSGET with additional filter?

01-07-2014 01:45 PM 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

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Mentor
mid-awe
Posts: 1,199
Registered: ‎12-08-2004
Message 7 of 8 (276 Views)

Re: SSGET with additional filter?

01-07-2014 02:13 PM 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). :smileyhappy:

Again, thank you.
Mentor
mid-awe
Posts: 1,199
Registered: ‎12-08-2004
Message 8 of 8 (273 Views)

Re: SSGET with additional filter?

01-07-2014 02:25 PM 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community