Jump to content

Recommended Posts

Posted (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 by Scoutr4
Posted (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 by Scoutr4
Posted

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.

  • Like 1
  • Thanks 1
Posted

Thank you for the explanation and examples.
 

  • Like 1

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