Author Topic: ssdel or counting  (Read 3164 times)

0 Members and 1 Guest are viewing this topic.

curmudgeon

  • Newt
  • Posts: 194
ssdel or counting
« on: June 16, 2009, 12:17:41 PM »
I create a selection set for one purpose only. the way I started out was
Code: [Select]
(setq count 0)
   (repeat (sslength them)
    (setq ent (entget (ssname them count))
  pt_lst nil)

    (cond (/= "TEXT" (cdr (assoc 8 ent)))
  (foreach a ent
   (if (= (car a) 10)
     (setq pt_lst (append pt_lst (list (cdr a))))
   )
  )
    );; end cond
(setq count (+ 1 count))
);;; end repeat

which would work. but I wonder, should I rather skip setting a variable count and just ssdel right before the loop repeats?
I am trying to build good habits because bad ones are so hard to break, and I am not getting any younger.
 :whistle:
« Last Edit: June 16, 2009, 12:21:05 PM by curmudgeon »
Never express yourself more clearly than you are able to think.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ssdel or counting
« Reply #1 on: June 16, 2009, 12:20:22 PM »
I don't really think it matters that much.  If I'm not going to use the selection set again, or won't want to use it after the command finishes, then I use ssdel, force of habit, but if you might want to reuse the selection set, then use a counter.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: ssdel or counting
« Reply #2 on: June 16, 2009, 12:33:02 PM »
I don't normally use a repeat method to shuffling through SelectionSets, I normally convert the set into a list of entities which is much more manageable, as lists are the basis of LISP programming. Also, the repeat method uses integers to shuffle through the Entity Names, and integers have a 32767 limit.

for example:

Code: [Select]
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))

Will return a list of entities in the selection set (ss).

If you have retrieved the selection set through (ssget "_X") method, then there is no need for the vl-remove-if:

hence:

Code: [Select]
(mapcar 'cadr (ssnamex ss))

Hope this helps  :-)

Lee

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssdel or counting
« Reply #3 on: June 16, 2009, 12:34:00 PM »
WHILE is faster.

My choice:
Code: [Select]
(defun c:test(/ i ss ent elst pt_lst)
  (defun get_vertex (elst)
    (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) elst))
  )
(setq ss (ssget))
(setq i -1)
(while (setq ent (ssname ss (setq i (1+ i))))
  (if (/= "TEXT" (assoc 8 (setq elst (entget ent))))
     (setq pt_lst
            (cond
              (pt_lst (append (get_vertex elst) pt_lst))
              ((get_vertex elst))))
  )
)
(princ)
)

<edit: bug fix>
« Last Edit: June 16, 2009, 12:44:28 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: ssdel or counting
« Reply #4 on: June 16, 2009, 12:44:01 PM »
And my two cents  :-)

Code: [Select]
(if (setq ss (ssget '((8 . "~TEXT"))))
  (progn ;;repeat
         (setq n -1)
         (repeat (sslength ss)
           (setq e (ssname ss (setq n (1+ n))))
           (setq out1 (cons e out1))
         )
         (setq n -1)
         ;;while
         (while (setq e (ssname ss (setq n (1+ n))))
           (setq out2 (cons e out2))
           (ssdel e ss)
         )
         ;;mapcar
         (setq out3 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: ssdel or counting
« Reply #5 on: June 16, 2009, 01:16:40 PM »
Nice one Ron, just collaborating the three methods...  :angel:

curmudgeon

  • Newt
  • Posts: 194
Re: ssdel or counting
« Reply #6 on: June 16, 2009, 02:14:33 PM »
thanks guys. I need time to digest....
 :-D
Never express yourself more clearly than you are able to think.

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: ssdel or counting
« Reply #7 on: June 16, 2009, 03:30:42 PM »
Hi,

Quote
I don't normally use a repeat method to shuffling through SelectionSets, I normally convert the set into a list of entities which is much more manageable, as lists are the basis of LISP programming.

You can have a look at this post, even for building a list while and repeat are faster.
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: ssdel or counting
« Reply #8 on: June 16, 2009, 03:38:33 PM »
Quite a difference I see...  thanks Gile  :-)