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

ssget filters too small a selection

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
mmitchellH6TRW
576 Views, 8 Replies

ssget filters too small a selection

What I am trying to do:
delete all blocks inserts not on my "keep" list.

 

 

    (setq DELETEGRP (ssget "X" 
                           '((0 . "INSERT") ; SELECT ONLY BLOCK INSERTS
                            )
                    )
          KEEPGRP   (ssget "X" 
                           '((0 . "INSERT") ; SELECT ONLY BLOCK INSERTS
                             (-4 . "<OR") ; SELECT ALL BLOCKS IN THIS LIST
                             (2 . "DA_LE1")
                             (2 . "DA_BIDUAL-MINI")
                             (2 . "DT_TAP2")
                             (2 . "DT_TAP4")
                             (2 . "STA")
                             (2 . "UtilitySymbols")
                             (2 . "RCU_COMM")
                             (2 . "RCU_HHP")
                             (2 . "RP_PEDSTL")
                             (2 . "RP_CTIC")
                             (2 . "RP_UTCLST")
                             (2 . "SPLICE")
                             (2 . "RF_TRENCH")
                             (2 . "B_MDUADD")
                             (2 . "Storage Loop")
                             (2 . "Makready Legend")
                             (2 . "RF_STRAND")
                             (2 . "TCPX-X")
                             (2 . "TCP TAG")
                             (2 . "RN_UNKDROP")
                             (2 . "RN_OHDROP")
                             (2 . "RN_UGDROP")
                             (2 . "RP_PWR")
                             (2 . "RP_JNT")
                             (2 . "RP_TRANSJNT")
                             (2 . "RP_TRANSPWR")
                             (2 . "RP_TEL")
                             (2 . "RP_VLT")
                             (2 . "RCA_HHP")
                             (2 . "RCA_COMM")
                             (2 . "RA_ANCHOR")
                             (2 . "RA_OHGUY")
                             (2 . "RP_CRSSOVER")
                             (2 . "CITY_COUNTY_LIMITS")
                             (2 . "CELL_TWR")
                             (2 . "STATE HWY")
                             (2 . "FED HWY")
                             (2 . "INTERSTATE HWY")
                             (2 . "B_UNITCOMM")
                             (2 . "N-NORTH")
                             (2 . "HLECP Title Block - Packet Sheets")
                             (2 . "SHEET NAMES")
                             (2 . "APPROACH PLAN BOARDER")
                             (2 . "COMCAST*LEGEND")
                             (2 . "RP_LOCKBOX")
                             (2 . "B_ADDCOMM")
                             (2 . "B_ADDCOMM-MDU")
                             (2 . "B_Address")
                             (2 . "B_UNITMDU")
                             (2 . "BORING NOTE")
                             (2 . "C- I405-I5-I90-DB")
                             (2 . "CORVALLIS_UTILITY_CONFILCT_AVOID")
                             (2 . "dynamic block_tree4")
                             (2 . "FLAGGER_TRAFFIC_LIGHT")
                             (2 . "HANDHOLE")
                             (2 . "PROBUILD LEGEND")
                             (2 . "RF_CONDUIT")
                             (2 . "SALEM_Existing_Utilities_Legend")
                             (2 . "SALEM_TEMP_STREET_CLOSURE")
                             (2 . "SHRUB")
                             (2 . "SPRINGFIELD_NO_TCP_NEEDED")
                             (2 . "STREET_LIGHT")
                             (2 . "TREE_NOTE")
                             (2 . "UTILITY_CONFLICT_AVOID")
                             (2 . "C- I405-I5-I90-DB")
                             (2 . "PROBUILD")
                             (2 . "dynamic block_tree4")
                             (2 . "TCP TAG")
                             (2 . "APPROACH PLAN BOARDER")
                             ; (2 . "temp")
                             ; (2 . "temp")
                             ; (2 . "temp")
                             ; (2 . "temp")
                             ; (2 . "temp")
                             ; (2 . "temp")
                             (-4 . "OR>")
                            )
                    )
    )
;; Remove the keep group selection from the delete group.
    (if KEEPGRP 
      (repeat (setq i (sslength KEEPGRP)) 
        (ssdel 
          (ssname KEEPGRP 
                  (setq i (1- i))
          )
          DELETEGRP
        )
       )
    )
    (sssetfirst nil DELETEGRP) ; Take a look at the results.

 

 

 

 

 My KEEPGRP only selects the first insert that it encounters of each OR member. Therefore, my delete group has block inserts that are also in the keep list.
I have included my test drawing, incase that anyone wants to experiment. There should be nothing selected in the end if this was to work correctly.

Labels (3)
8 REPLIES 8
Message 2 of 9

I didn't try the code, but my first thought is that you should be able to just select all the to-be-deleted Blocks directly by omitting the to-be-kept ones from the selection at the time, rather than finding all the to-be-kept ones and stepping through and removing them from the all-Blocks selection.  Something like [untested]:

    (setq DELETEGRP (ssget "X" 
                           '((0 . "INSERT") ; SELECT ONLY BLOCK INSERTS
                             (-4 . "<NOT")
                               (-4 . "<OR") ; SELECT ALL BLOCKS IN THIS LIST
                                 (2 . "DA_LE1")
                                 (2 . "DA_BIDUAL-MINI")
....
                                 (2 . "TCP TAG")
                                 (2 . "APPROACH PLAN BOARDER")
                                (-4 . "OR>")
                              (-4 . "NOT>")
                            )
                    )
    )
    (sssetfirst nil DELETEGRP) ; Take a look at the results.

 

Kent Cooper, AIA
Message 3 of 9

Yes, that is what I did first. But something wasn't right in the OR section. I kept getting most of my Keep list deleted when deleted the resulting ss.  So I separated them and found that the OR section doesn't pick all inserts just a sample with the <OR ... OR> filter.

Message 4 of 9
paullimapa
in reply to: Kent1Cooper

Would it work with block names separate d by commas?

(list
'(0 . "INSERT") ; SELECT ONLY BLOCK INSERTS
'(-4 . "<NOT")
  (cons 2 "DA_LE1,DA_BIDUAL-MINI")
....

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 9

You have inserts in model space and in paper space!

(sssetfirsrt nil x) return only in current space

Message 6 of 9

hey,

 

(setq block_references_list (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "insert")))))))
	  keep_list '(
	   			 	"DA_LE1" "DA_BIDUAL-MINI" "DT_TAP2" "DT_TAP4" "STA" "UtilitySymbols" "RCU_COMM" "RCU_HHP" "RP_PEDSTL"
				    "RP_CTIC" "RP_UTCLST" "SPLICE" "RF_TRENCH" "B_MDUADD" "Storage Loop" "Makready Legend" "RF_STRAND"
                    "TCPX-X" "TCP TAG" "RN_UNKDROP" "RN_OHDROP" "RN_UGDROP" "RP_PWR" "RP_JNT" "RP_TRANSJNT" "RP_TRANSPWR"
                    "RP_TEL" "RP_VLT" "RCA_HHP" "RCA_COMM" "RA_ANCHOR" "RA_OHGUY" "RP_CRSSOVER" "CITY_COUNTY_LIMITS"
                    "CELL_TWR" "STATE HWY" "FED HWY" "INTERSTATE HWY" "B_UNITCOMM" "N-NORTH" "HLECP Title Block - Packet Sheets"
                    "SHEET NAMES" "APPROACH PLAN BOARDER" "COMCAST*LEGEND" "RP_LOCKBOX" "B_ADDCOMM" "B_ADDCOMM-MDU" "B_Address"
                    "B_UNITMDU" "BORING NOTE" "C- I405-I5-I90-DB" "CORVALLIS_UTILITY_CONFILCT_AVOID" "dynamic block_tree4"
                    "FLAGGER_TRAFFIC_LIGHT" "HANDHOLE" "PROBUILD LEGEND" "RF_CONDUIT" "SALEM_Existing_Utilities_Legend"
                    "SALEM_TEMP_STREET_CLOSURE" "SHRUB" "SPRINGFIELD_NO_TCP_NEEDED" "STREET_LIGHT" "TREE_NOTE"
					"UTILITY_CONFLICT_AVOID" "C- I405-I5-I90-DB" "PROBUILD" "dynamic block_tree4" "TCP TAG"
                    "APPROACH PLAN BOARDER"
				 )
)
(foreach block_reference block_references_list
	(if (not (member (vla-get-effectivename block_reference)) keep_list)
		(vla-erase block_reference)
	)
)
Message 7 of 9
ronjonp
in reply to: mmitchellH6TRW

Here's another way organizing the "keepers" in a list then appending "~" to the name which excludes them.

 

(setq keepers '("APPROACH PLAN BOARDER"			      "APPROACH PLAN BOARDER"
		"BORING NOTE"	       "B_ADDCOMM"	      "B_ADDCOMM-MDU"
		"B_Address"	       "B_MDUADD"	      "B_UNITCOMM"
		"B_UNITMDU"	       "C- I405-I5-I90-DB"    "C- I405-I5-I90-DB"
		"CELL_TWR"	       "CITY_COUNTY_LIMITS"   "COMCAST*LEGEND"
		"CORVALLIS_UTILITY_CONFILCT_AVOID"	      "DA_BIDUAL-MINI"
		"DA_LE1"	       "DT_TAP2"	      "DT_TAP4"
		"FED HWY"	       "FLAGGER_TRAFFIC_LIGHT"
		"HANDHOLE"	       "HLECP Title Block - Packet Sheets"
		"INTERSTATE HWY"       "Makready Legend"      "N-NORTH"
		"PROBUILD"	       "PROBUILD LEGEND"      "RA_ANCHOR"
		"RA_OHGUY"	       "RCA_COMM"	      "RCA_HHP"
		"RCU_COMM"	       "RCU_HHP"	      "RF_CONDUIT"
		"RF_STRAND"	       "RF_TRENCH"	      "RN_OHDROP"
		"RN_UGDROP"	       "RN_UNKDROP"	      "RP_CRSSOVER"
		"RP_CTIC"	       "RP_JNT"		      "RP_LOCKBOX"
		"RP_PEDSTL"	       "RP_PWR"		      "RP_TEL"
		"RP_TRANSJNT"	       "RP_TRANSPWR"	      "RP_UTCLST"
		"RP_VLT"	       "SALEM_Existing_Utilities_Legend"
		"SALEM_TEMP_STREET_CLOSURE"		      "SHEET NAMES"
		"SHRUB"		       "SPLICE"		      "SPRINGFIELD_NO_TCP_NEEDED"
		"STA"		       "STATE HWY"	      "STREET_LIGHT"
		"Storage Loop"	       "TCP TAG"	      "TCP TAG"
		"TCPX-X"	       "TREE_NOTE"	      "UTILITY_CONFLICT_AVOID"
		"UtilitySymbols"       "dynamic block_tree4"  "dynamic block_tree4"
	       )
)
(if (setq s (ssget "_X"
		   (list '(0 . "INSERT")
			 (cons 2 (apply 'strcat (mapcar '(lambda (x) (strcat "~" x ",")) keepers)))
		   )
	    )
    )
  (mapcar 'entdel (mapcar 'cadr (ssnamex s)))
)

 

 

 

Message 8 of 9

I would like to accept this one too,
However,
Even after correcting:

(if (not (member (vla-get-effectivename block_reference) keep_list))
...
)

I can not get it to work.
Everything works up to the if statement above then I get an 
"unknow exception occurred"

Message 9 of 9
ronjonp
in reply to: mmitchellH6TRW

@mmitchellH6TRW 

I just noticed that you have modified dynamic blocks. You need to use this version of code to account for them.

ronjonp_0-1681925827970.png

 

 

(setq keepers (mapcar 'strcase
		      '("APPROACH PLAN BOARDER"			      "APPROACH PLAN BOARDER"
			"BORING NOTE"	       "B_ADDCOMM"	      "B_ADDCOMM-MDU"
			"B_Address"	       "B_MDUADD"	      "B_UNITCOMM"
			"B_UNITMDU"	       "C- I405-I5-I90-DB"    "C- I405-I5-I90-DB"
			"CELL_TWR"	       "CITY_COUNTY_LIMITS"   "COMCAST*LEGEND"
			"CORVALLIS_UTILITY_CONFILCT_AVOID"	      "DA_BIDUAL-MINI"
			"DA_LE1"	       "DT_TAP2"	      "DT_TAP4"
			"FED HWY"	       "FLAGGER_TRAFFIC_LIGHT"
			"HANDHOLE"	       "HLECP Title Block - Packet Sheets"
			"INTERSTATE HWY"       "Makready Legend"      "N-NORTH"
			"PROBUILD"	       "PROBUILD LEGEND"      "RA_ANCHOR"
			"RA_OHGUY"	       "RCA_COMM"	      "RCA_HHP"
			"RCU_COMM"	       "RCU_HHP"	      "RF_CONDUIT"
			"RF_STRAND"	       "RF_TRENCH"	      "RN_OHDROP"
			"RN_UGDROP"	       "RN_UNKDROP"	      "RP_CRSSOVER"
			"RP_CTIC"	       "RP_JNT"		      "RP_LOCKBOX"
			"RP_PEDSTL"	       "RP_PWR"		      "RP_TEL"
			"RP_TRANSJNT"	       "RP_TRANSPWR"	      "RP_UTCLST"
			"RP_VLT"	       "SALEM_Existing_Utilities_Legend"
			"SALEM_TEMP_STREET_CLOSURE"		      "SHEET NAMES"
			"SHRUB"		       "SPLICE"		      "SPRINGFIELD_NO_TCP_NEEDED"
			"STA"		       "STATE HWY"	      "STREET_LIGHT"
			"Storage Loop"	       "TCP TAG"	      "TCP TAG"
			"TCPX-X"	       "TREE_NOTE"	      "UTILITY_CONFLICT_AVOID"
			"UtilitySymbols"       "dynamic block_tree4"
		       )
	      )
)
(if (setq
      s	(ssget
	  "_X"
	  (list
	    '(0 . "INSERT")
	    (cons 2
		  (strcat "`*U*," (apply 'strcat (mapcar '(lambda (x) (strcat "~" x ",")) keepers)))
	    )
	  )
	)
    )
  (foreach e (mapcar 'cadr (ssnamex s))
    (if	(and (wcmatch (setq n (vla-get-effectivename (vlax-ename->vla-object e))) "`*U*")
	     (not (member (strcase n) keepers))
	)
      (entdel e)
    )
  )
)

 

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report