Jump to content

Remove selection set from another (Retain the first selection set)


3dwannab

Recommended Posts

I hope this make sense.

 

I was to select some text with 

 

(setq ssRemove (ssget '((0 . "*TEXT"))))

 

Then have a another selection set that has text, leaders, multileaders and dimensions.

 

(setq ssKeep (ssget "_X" '((0 . "*TEXT,LEADER,MULTILEADER,DIMENSION"))))

 

Then remove all but the selected text in the fist part there.

 

Here's what I've come up with and I was wondering if this would a good way or would there be better or faster methods than this?

 

;; 3dwannab
;; Removes a selection set from another but retains the items from the first.
;; Returns a new selection set.
;; Wrote on 2022.01.31
;; Usage:
;; (setq ssNew (3d:RemoveSSFromSS ssRemove ssKeep))

(defun 3d:RemoveSSFromSS ( ssKeep ssRemove / i ent ssNew )

  (setq ssNew (ssadd))

  (repeat (setq i (sslength ssRemove))

    (setq ent (ssname ssRemove (setq i (1- i))))

    ;; Just don't add the entity from the first selection
    (if (not (ssmemb ent ssKeep))
      (setq ssNew (ssadd ent ssNew))
      )
    )

  ssNew

  )

(setq ssRemove (ssget '((0 . "*TEXT"))))

(setq ssKeep (ssget "_X" '((0 . "*TEXT,LEADER,MULTILEADER,DIMENSION"))))

(setq ssNew (3d:RemoveSSFromSS ssRemove ssKeep))

(sssetfirst nil ssNew)

(princ)

 

 

Here's what it does. It's like an inverse selection of sorts.

 

EXEZaFC.gif

Edited by 3dwannab
Link to comment
Share on other sites

  • 3dwannab changed the title to Remove selection set from another (Retain the first selection set)

Wrote this to invert the selection of things on screen

 

;;----------------------------------------------------------------------------;;
;; Invert Selection on Screen
(defun C:SEE (/ SS SS1)
  (if (setq SS
        (cond
          ((ssget "_I"))  ; preselection, if any
          ((ssget))       ; User selection if no pre-selection
        )
      )
    (progn
      (if (setq SS1 (ssget "_WP" (GetScreenCoords)))
        (progn
          (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
            (ssdel ent SS1)
          )
          (sssetfirst nil SS1)
        )
        (prompt "\nNothing on Screen Zoom Out")
      )
    )
  )
  (princ)
)
;Calculates View Window
(defun GetScreenCoords (/ ViwCen ViwDim ViwSiz VptMin VptMax)
  (setq ViwSiz (/ (getvar "VIEWSIZE") 2)
        ViwCen (getvar "VIEWCTR")
        ViwDim (list (* ViwSiz (apply '/ (getvar "SCREENSIZE"))) ViwSiz)
        VptMin (mapcar '- ViwCen ViwDim)
        VptMax (mapcar '+ ViwCen ViwDim)
  )
  (list VptMin VptMax)
)

 

Edited by mhupp
princ / code update
  • Like 1
Link to comment
Share on other sites

It was just an example of how to remove things from a selection set. You have to select something during the command or have something selected then run the command.  It will take the inverse of whats completely on screen. Repeat the command to switch back and forth. will also error if nothing is on the screen.

 

 

 

To directly answer you question. the foreach with ssdel from my example is a better option on how to remove one selection set from another.

also you don't have to build a 3rd selection set

(setq ssRemove (ssget '((0 . "*TEXT"))))
(setq ssKeep (ssget "_X" '((0 . "*TEXT,LEADER,MULTILEADER,DIMENSION"))))
(foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ssRemove))) 
  (ssdel ent ssKeep) ;only removes the entity from the selection set doesn't delete the entity from the drawing.
)
(sssetfirst nil ssKeep)
(princ)

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

Here's another thought to exclude a picked item type:

(defun c:foo (/ a e f s)
  (cond	((setq e (car (entsel "\nPick something to exclude: ")))
	 (setq f "*TEXT,LEADER,MULTILEADER,DIMENSION")
	 (setq a (cdr (assoc 0 (entget e))))
	 (sssetfirst
	   nil
	   (ssget "_A"
		  (list	(cons 0
			      (if (wcmatch a "*TEXT")
				(vl-string-subst "~*TEXT" "*TEXT" f)
				(vl-string-subst (strcat "~" a) a f)
			      )
			)
		  )
	   )
	 )
	)
  )
  (princ)
)
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...