Scoutr4 Posted November 15, 2022 Posted November 15, 2022 (edited) I have 2 ssget selections named mylist and oldlist. I want to delete similar ones in mylist but ssname line gives nil. How can I fix ? (repeat (setq i (sslength mylist)) (setq ent (ssname mylist (setq i (1 - i)))) (if (ssmemb ent oldlist)(progn (ssdel ent mylist)))) Edited November 15, 2022 by Scoutr4 Quote
Scoutr4 Posted November 15, 2022 Author Posted November 15, 2022 (edited) I found solution like this : (defun c:test() (setq mylist (ssget)) (setq oldlist (ssget)) (setq a 0) (repeat (setq i (sslength mylist)) (setq ent (ssname mylist a)) (if (ssmemb ent oldlist)(progn (ssdel ent mylist)))) (setq a (+ 1 a)) (princ (sslength mylist)) (princ)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Edit 2: (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex mylist))) (if (ssmemb ent oldlist)(progn (ssdel ent mylist)))) Edit : it doesn't work exactly right. Most of the time it doesn't delete the object from the list. How do we get it to work correctly? Edit 2 : i solved the problem with foreach Edited November 15, 2022 by Scoutr4 Quote
mhupp Posted November 15, 2022 Posted November 15, 2022 I oped to use foreach because Its cleaner. but for clarity this is what was happening. The repeat method wasn't working because its was always checking (ssname mylist 0). So once it finds an entity that's not a member of oldlist it breaks and stops checking the rest of the entity's. If you have 5 entity's in mylist they number 0 1 2 3 4 Repeat first run checks entity 0 its in oldlist so its removed now the rest of the entity's drop down a # to 0 1 2 3 Repeat runs a second time checking entity 0 (that was previously entity 1) its not in oldlist so its not removed and nothing changes Repeat will run the same check on entity 0 and nothing changes it will keep doing this until loop is done. So what needs to happen is if memeber remove from list if not add +1 to "a" so it skips that entity the next loop. (defun c:test () (setq mylist (ssget)) (setq oldlist (ssget)) (setq a 0) (repeat (sslength mylist) (setq ent (ssname mylist a)) (if (ssmemb ent oldlist) (ssdel ent mylist) (setq a (1+ a)) ) ) (sssetfirst nil mylist) (princ) ) Also don't need (progn after if unless you want to run multiple lines of code. 1 1 Quote
pkenewell Posted November 15, 2022 Posted November 15, 2022 (edited) Refer to this - selection boolean functions: http://www.theswamp.org/index.php?topic=46652.msg516656#msg516656 Another Example: http://www.theswamp.org/index.php?topic=48591.msg536882#msg536882 Edited November 15, 2022 by pkenewell 2 Quote
Scoutr4 Posted November 15, 2022 Author Posted November 15, 2022 Thank you for the explanation and examples. 1 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.