Jump to content

Recommended Posts

Posted

I have 2  list of text items. I need remove all items in the first list from the second list

Posted

(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))

Posted (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 by Emmanuel Delay
Posted

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 ?

Posted

Can you give examples?

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

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

In vanilla AutoLisp

 

-David

Posted

2.PNG.1535d739f735d50c5646d71693c83f43.PNG

1.PNG.ee9b5f23fb1bd014d35a8c8e4644f46b.PNGthis is the list

 

 

 

1.PNG

Posted (edited)

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

 

-David

Edited by David Bethel
  • Like 1
  • 3 years later...
Posted


(defun remove (removelist lst)
    (foreach x removelist
        (setq lst (subst nil x lst))
    )
)

 

Posted
On 6/3/2019 at 7:11 AM, wimal said:

2.PNG.1535d739f735d50c5646d71693c83f43.PNG

1.PNG.ee9b5f23fb1bd014d35a8c8e4644f46b.PNGthis is the list

 

 

 

1.PNG

this are not LIST , they are SELECTIONSET. 

 

Posted

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)

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