wimal Posted June 3, 2019 Posted June 3, 2019 I have 2 list of text items. I need remove all items in the first list from the second list Quote
rlx Posted June 3, 2019 Posted June 3, 2019 (setq l1 (list 1 2 3 4 5 6 7 8 9 0) l2 (list 2 4 6) l3 (vl-remove-if ''((x)(member x l2)) l1)) Quote
Emmanuel Delay Posted June 3, 2019 Posted June 3, 2019 (edited) 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 June 3, 2019 by Emmanuel Delay Quote
wimal Posted June 3, 2019 Author Posted June 3, 2019 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 ? Quote
Emmanuel Delay Posted June 3, 2019 Posted June 3, 2019 Can you give examples? List 1, List 2, and what you want removed / what must be the end result ? Quote
David Bethel Posted June 3, 2019 Posted June 3, 2019 (defun remove (expr lst);;;TonyT or VNesterowski (apply 'append (subst nil (list expr) (mapcar 'list lst)))) In vanilla AutoLisp -David Quote
David Bethel Posted June 3, 2019 Posted June 3, 2019 (edited) If you are dealing with entity names and picksets, look into (ssmemb) & (ssdel) -David Edited June 3, 2019 by David Bethel 1 Quote
seawind Posted December 31, 2022 Posted December 31, 2022 (defun remove (removelist lst) (foreach x removelist (setq lst (subst nil x lst)) ) ) Quote
devitg Posted January 2, 2023 Posted January 2, 2023 On 6/3/2019 at 7:11 AM, wimal said: this is the list this are not LIST , they are SELECTIONSET. Quote
mhupp Posted January 3, 2023 Posted January 3, 2023 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) Quote
Recommended Posts
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.