Author Topic: Removing One Selection Set from Another  (Read 2774 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Removing One Selection Set from Another
« on: January 07, 2015, 12:12:00 PM »
Ok, so I have two selection sets, one has say 200 items in it and another has 10 items in it. I need to remove the 10 items from the selection set with 200 items in it so that I can delete the 10 item selection set and have no empty items in the 200 (should now be 190) item selection set, any suggestions?
I have tried something like:
Code: [Select]
(setq Ct 0)
(while (< Ct (sslength SS1))
(ssremove (ssname SS1 Ct) SS2)
(setq Ct (+ Ct 1))
)

But this doesn't work, as once I erase SS1, SS2 still contains null objects.
« Last Edit: January 07, 2015, 12:29:31 PM by cmwade77 »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Removing One Selection Set from Another
« Reply #1 on: January 07, 2015, 12:23:57 PM »
I thought ssremove would take care of it. If not, just create a new selection set with ssadd that doesn't include the 10 objects.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Removing One Selection Set from Another
« Reply #2 on: January 07, 2015, 12:34:45 PM »
So did I and I wanted the routine to be faster, so I thought SSREMOVE would be faster than going through each of the 200 items and comparing them to the list of 10 that I don't want. Seems to me that this method is inneficeint, unless there is a better way to create the new selection set.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Removing One Selection Set from Another
« Reply #3 on: January 07, 2015, 12:45:42 PM »
Don't you mean SSDEL ?
Code - Auto/Visual Lisp: [Select]
  1. ;; Total SS
  2. (setq ss1 (ssget))
  3. ;; SS to remove
  4. (setq ss2 (ssget))
  5.  
  6.  
  7. (setq ct 0)
  8. (while (< ct (sslength ss2)) (ssdel (ssname ss2 ct) ss1) (setq ct (+ ct 1)))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Removing One Selection Set from Another
« Reply #4 on: January 07, 2015, 12:50:02 PM »
Don't you mean SSDEL ?
Code - Auto/Visual Lisp: [Select]
  1. ;; Total SS
  2. (setq ss1 (ssget))
  3. ;; SS to remove
  4. (setq ss2 (ssget))
  5.  
  6.  
  7. (setq ct 0)
  8. (while (< ct (sslength ss2)) (ssdel (ssname ss2 ct) ss1) (setq ct (+ ct 1)))
ssremove and ssdel appear to do the same thing, but I tried changing it and it doesn't work either.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Removing One Selection Set from Another
« Reply #5 on: January 07, 2015, 01:01:41 PM »
Works here:

Code - Auto/Visual Lisp: [Select]
  1. ;; Total SS
  2. (setq ss1 (ssget))
  3. ;; SS to remove
  4. (princ (strcat "SS1 - " (itoa (sslength ss1))))
  5. (setq ss2 (ssget))
  6. (strcat "SS2 - " (itoa (sslength ss2)))
  7. (repeat (setq i (sslength ss2)) (ssdel (ssname ss2 (setq i (1- i))) ss1))
  8. (princ (strcat "SS1 - " (itoa (sslength ss1))))
  9.  ;|_$
  10. <Selection set: 4dc0> SS1 - 11
  11. "SS1 - 11"
  12. <Selection set: 4dc2>
  13. "SS2 - 4"
  14. -1
  15. <Selection set: 4dc0> SS1 - 7
  16. "SS1 - 7"
  17. ; 7 forms loaded from #<editor "<Untitled-0> loading...">
  18. _$ |;
« Last Edit: January 07, 2015, 01:27:32 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Removing One Selection Set from Another
« Reply #6 on: January 07, 2015, 01:16:21 PM »
Yes, that one works and I think my version even did, the issue was that I had a second place that I needed to process it in two places in my code.  :-o

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Removing One Selection Set from Another
« Reply #7 on: January 07, 2015, 01:22:24 PM »
Glad you got it sorted. On a side topic SSREMOVE is not a built in function on my computer .. is this something you've defined ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Removing One Selection Set from Another
« Reply #8 on: January 07, 2015, 01:30:55 PM »
No, it worked in one spot but not in another.....not sure why....unless it's something defined in one of the third party routines we have loaded.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Removing One Selection Set from Another
« Reply #9 on: January 07, 2015, 04:28:54 PM »
Maybe it is faster with big sel. sets:
Code: [Select]
; Function: ALE_SS_AddRem
;
; Version 1.02
;
; Description:
;   add/remove selset to/from selset
;
; Use:
;   (ALE_SS_AddRem SsOrignal "_REMOVE" Ss2Remove)
;   (ALE_SS_AddRem SsOrignal "_ADD"    Ss2Add)
;
; Note:
;   select entities only in current space
;   change the Previous selection set
;
(defun ALE_SS_AddRem (Ss_Org AddRem SsAdRm / )
  (cond
    ( (and Ss_Org SsAdRm (> (sslength SsAdRm) 0))
;     (setvar "CMDECHO" 0)
      (setvar "HIGHLIGHT" 0)
      (vl-cmdf "_.SELECT" Ss_Org AddRem SsAdRm "");leave vl-cmdf for problems in Bricscad
      (setvar "HIGHLIGHT" 1)
      (ssget "_P")
    )
    ( Ss_Org )
  )
)

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Removing One Selection Set from Another
« Reply #10 on: January 07, 2015, 04:42:52 PM »
The repeat solution is pretty fast:
Quote
_$
<Selection set: 75c5>
"SS1 - 119700"
<Selection set: 75c7>
"SS2 - 72553"
<Selection set: 75c5>
"SS1 - 47148"
< Elapsed time: 0.109000 seconds. >
_$



ALE_SS_ADDREM
<Selection set: 75c7>
< Elapsed time: 2.769267 minutes. > _$
« Last Edit: January 07, 2015, 04:50:03 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Removing One Selection Set from Another
« Reply #11 on: January 08, 2015, 12:27:06 PM »
The repeat solution is pretty fast:
Quote
_$
<Selection set: 75c5>
"SS1 - 119700"
<Selection set: 75c7>
"SS2 - 72553"
<Selection set: 75c5>
"SS1 - 47148"
< Elapsed time: 0.109000 seconds. >
_$



ALE_SS_ADDREM
<Selection set: 75c7>
< Elapsed time: 2.769267 minutes. > _$
Yup! It is absolutely true, many years ago I had this version:
Code: [Select]
(defun ALE_SsUnion (Ss_Org Ss2Add / Counter)
  (and
    Ss2Add
    (setq Counter 0)
    (repeat (sslength Ss2Add)
      (ssadd (ssname Ss2Add Counter) Ss_Org)
      (setq Counter (1+ Counter))
    )
  )
  Ss_Org
)
and I changed it because it seemed faster... Dunno, maybe I made a mistake! Now I provide to return with ssdel / ssadd. Grazie!  :(

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Removing One Selection Set from Another
« Reply #12 on: January 08, 2015, 04:52:30 PM »
Maybe this is pretty good:
Code: [Select]
; Function: ALE_SS_AddRem
;
; Version 2.00 - 20150108
;
; Description:
;   add/remove selset to/from selset
;
; Arguments:
;   Ss_Org = Original Selection Set
;   AddRem = ADD ('ssadd) TO or REMOVE ('ssdel) FROM Original Selection Set
;   SsAdRm = Selection Set to ADD or REMOVE
;
; Use:
;   (ALE_SS_AddRem SsOrignal 'ssdel Ss2Remove)
;   (ALE_SS_AddRem SsOrignal 'ssadd    Ss2Add)
;
(defun ALE_SS_AddRem (Ss_Org AddRem SsAdRm / Countr SsFunc)
  (cond
    ( (and Ss_Org SsAdRm (> (sslength SsAdRm) 0))
      (setq SsFunc (eval AddRem))
      (repeat (setq Countr (sslength SsAdRm))
        (SsFunc (ssname SsAdRm (setq Countr (1- Countr))) Ss_Org)
      )
    )
    ( Ss_Org )
  )
)