Jump to content

Items of a list remove from another list


wimal

Recommended Posts

You mean like this?

 

(defun c:rfsl (/ fl sl i j ft st)
  (princ "\nSelect First List (and press Enter): ")
  (setvar "nomutt" 1)                              ;; mute the "Select Objects" promt of (ssget)
  (setq fl (ssget (list (cons 0 "MTEXT,TEXT")) ))
  (princ "\nSelect Second List (and press Enter): ")
  (setq sl (ssget (list (cons 0 "MTEXT,TEXT")) ))
  (setvar "nomutt" 0)
 
  (setq i 0)
  (repeat (sslength fl)
    (setq j 0)
    (setq match nil)
    (setq ft (cdr (assoc 1 (entget (ssname fl i)))))  ;; value of first text
    (while (and (< j (sslength sl)) (= match nil))
      (if (=
          ft
          (setq st (cdr (assoc 1 (entget (ssname sl j)))))
        )
        (setq match j)  ;; set the index j to match.  This will also stop the loop
      )
      (setq j (+ j 1))
    )
    (if (not (= match nil)) (progn
      (princ "\nDeleting ")
      (princ st)
      (entdel (ssname sl match))        ;; remove the item
      (ssdel  (ssname sl match) sl)     ;; also remove the item from the ssget selection
    ))
    (setq i (+ i 1))
  )
  (princ)
)

Edited by Emmanuel Delay
Link to comment
Share on other sites

My quistion is not wrritten clearly. Srry for that. Mr.Emmanuels' riply is closing to my requirements. But the value of text (assoc 1) do not fullfill my requirements, beacuse same text valus are in differance locations may be in my list. So if I can find the handle of the text item and compair with others it can filter correctlly. But how can I absorb the handle of text item ?

Link to comment
Share on other sites

Can you give examples?

List 1, List 2, and what you want removed / what must be the end result ?

Link to comment
Share on other sites

(defun remove (expr lst);;;TonyT or VNesterowski
  (apply 'append (subst nil (list expr) (mapcar 'list lst))))

In vanilla AutoLisp

 

-David

Link to comment
Share on other sites

If you are dealing with entity names and picksets, look into (ssmemb) & (ssdel)

 

-David

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

  • 3 years later...

To build off of what devitg and david said

 

This will select entities that are only in SS1 selection.

(setq ss (ssget))
(setq ss1 (ssget))
(foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
  (ssdel ent SS1)
)
(sssetfirst nil ss1)

 

This will selects entities that are in both SS & SS1.

(setq ss (ssget))
(setq ss1 (ssget))
(setq ss2 (ssadd)) ;blank selection set is needed to add items to.
(foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
  (if (ssmemb ent SS1)
    (ssadd ent SS2)
  )
)
(sssetfirst nil ss2)

 

@seawind if your dealing with list its best to just remove the item from the list rather then replacing it with a nil. unless you need to keep the original position or something.

(defun remove (removelist lst)
    (foreach x removelist
        (setq lst (vl-remove x lst))
    )
)

 

(remove '(1 3) '(1 2 3 4 5 6))

'(2 4 5 6)

 

Where yours would look like this

(remove '(1 3) '(1 2 3 4 5 6))

'(nil 2 nil 4 5 6)

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