Group selection substraction

Group selection substraction

joseZ9KZ7
Contributor Contributor
803 Views
4 Replies
Message 1 of 5

Group selection substraction

joseZ9KZ7
Contributor
Contributor

Hi everyone!

 

I'm trying to select several objects (group A) and subtract it another group of objects (group B).

 

Any idea of a LISP to achieve this ?

 

Thank you very much.

0 Likes
804 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

Where is the issue? Treat it as any other selection set.

0 Likes
Message 3 of 5

Moshe-A
Mentor
Mentor

@joseZ9KZ7  hi,

 

something like this?

 

; substract Group B From Group A
(defun c:ss-sub (/ ss0 ss1 i)

 (if (and
       (not (prompt "\nSelect Group A..."))
       (setq ss0 (ssget))
       (not (prompt "\nSelect Group B..."))
       (setq ss1 (ssget))
     )
  (progn
   (setq i -1) 
   (repeat (sslength ss1)
    (setq ename (ssname ss1 (setq i (1+ i))))

    (if (ssmemb ename ss0)
     (ssdel ename ss0)
    )
   ); repeat  

  ); progn
 ); if

 (sssetfirst ss0 ss0)
 (princ) 
)
0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant

(defun C:SSAminusB ()

  (prompt "\nTo subtract selection set B from selection set A resulting in selection set C,")

  (if (and (setq ssA (ssget)) (setq ssB (ssget)))

    (progn ; then

      (command "_.SELECT" ssA "_remove" ssB "")

      (setq ssC (ssget "_P"))
    ); progn

  ); if

); defun

 

If you want to be left with the resulting reduced selection set selected/gripped/highlighted:

 

(sssetfirst nil ssC)

 

You can localize the ssA and ssB variables if you don't need them to remain afterwards.

 

It is not necessary to check whether any object in ssB is contained in ssA.

Kent Cooper, AIA
0 Likes
Message 5 of 5

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....

      (setq ssC (ssget "_P"))

....


Or, if you don't need or want a separate selection set C, but just want A to remain but with the thing(s) from B removed from it, just change that to:

    (setq ssA (ssget "_P"))

 

[and adjust the prompt at the beginning].

Kent Cooper, AIA
0 Likes