Author Topic: Question about SSDel  (Read 5109 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Question about SSDel
« on: April 01, 2010, 03:26:58 PM »
If I define a selection set to a variable, then copy that variable (assign it to another), and the ssdel an ename out of the variable, why does it remove it from the first variable selection set?

eg.

Code: [Select]
Command: (sslength (setq s1 (ssget)))

Select objects: Specify opposite corner: 8 found

Select objects:
8

Command: (setq s2 s1)
<Selection set: ffea>

Command: (sslength (ssdel (ssname s2 0) s2))
7

Command: (sslength s1)
7
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Question about SSDel
« Reply #1 on: April 01, 2010, 03:30:16 PM »
for performance and economy reasons selection sets are "special" (not like se7en) in that they behave more like pointers, thus when you set one selection set to another they both actually point to the same object
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Question about SSDel
« Reply #2 on: April 01, 2010, 03:32:42 PM »
Short answer...... Because both variable are referencing the same SelectionSet - <Selection set: ffea>

Longer answer, someone should be along with one :-) Crud, Trauma happens quick!

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Question about SSDel
« Reply #3 on: April 01, 2010, 03:35:21 PM »
OK, that make sense. I guess I was thinking about it like a list. Thanks guys.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Question about SSDel
« Reply #4 on: April 01, 2010, 03:38:43 PM »
I was trying to accomplish this:
Code: [Select]
(defun test (ss)
  (while (setq e (ssname ss 0))
    (cons e (test (ssdel e ss)))
  ) ;_ while
) ;_ defun

[color=red]OR[/color]

(defun test (ss / s2)
  (while (setq e (ssname (setq s2 ss) 0))
    (cons e (test (ssdel e s2)))
  ) ;_ while
) ;_ defun

But, I'll just use this:

Code: [Select]
(defun AT:SS->List (SS VLA / l)
  ((lambda (i)
     (if VLA
       (while (setq e (ssname SS (setq i (1+ i)))) (setq l (cons (vlax-ename->vla-object e) l)))
       (while (setq e (ssname SS (setq i (1+ i)))) (setq l (cons e l)))
     ) ;_ if
   ) ;_ lambda
    -1
  )
) ;_ defun
« Last Edit: April 01, 2010, 03:43:00 PM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

LE3

  • Guest
Re: Question about SSDel
« Reply #5 on: April 01, 2010, 03:40:08 PM »
to play with a little with lisp again, that you have to do something in the ugly lines below:
Code: [Select]
(setq s2 (ssadd))
(setq i 0)
(repeat (sslength s1)
  (ssadd (ssname s1 i) s2)
  (setq i (1+ i)))
 
then you will have another selection...
« Last Edit: April 01, 2010, 04:15:47 PM by LE3 »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Question about SSDel
« Reply #6 on: April 01, 2010, 03:42:43 PM »
to play with a little with lisp again, that you have to do something in the ugly lines below:
Code: [Select]
(setq s2 (ssadd))
(setq i 0)
(repeat (sslength s1)
  (ssadd (ssname s1 i) s2)
  (setq i (1+ i)))
 
then you will have another selection...

Ahh, thanks Luis. :)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Question about SSDel
« Reply #7 on: April 01, 2010, 03:48:16 PM »
or this...

Code: [Select]
(defun AT:SS->List (SS VLA / l)
  ((lambda (i)
     (if VLA
       (repeat (sslength SS)
         (setq l (cons (vlax-ename->vla-object (ssname SS (setq i (1+ i)))) l))
       ) ;_ repeat
       (repeat (sslength SS) (setq l (cons (ssname SS (setq i (1+ i))) l)))
     ) ;_ if
   ) ;_ lambda
    -1
  )
) ;_ defun
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Question about SSDel
« Reply #8 on: April 01, 2010, 03:48:57 PM »
I won't bother showing how to copy a selection set since LE3 anted up, so here's a different offering for one of your "alt" approaches ...

Code: [Select]
(defun _PicksetToEnames ( ss )
    (if (eq 'pickset (type ss))
        (mapcar
           '(lambda ( x ) (cadr x))
            (vl-remove-if '(lambda ( x ) (minusp (car x))) (ssnamex ss))
        )
    )
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Question about SSDel
« Reply #9 on: April 01, 2010, 03:58:00 PM »
I won't bother showing how to copy a selection set since LE3 anted up, so here's a different offering for one of your "alt" approaches ...

Code: [Select]
(defun _PicksetToEnames ( ss )
    (if (eq 'pickset (type ss))
        (mapcar
           '(lambda ( x ) (cadr x))
            (vl-remove-if '(lambda ( x ) (minusp (car x))) (ssnamex ss))
        )
    )
)

I used something very similar (used vl-remove-if 'listp), but wanted to replace it with something a bit faster (slow day and wanted to do a little optimizing).

Code: [Select]
Command: (benchmark '( (_picksettoenames s) (at:ss->list s nil) ))
Elapsed milliseconds / relative speed for 32768 iteration(s):

    (AT:SS->LIST S nil)......1890 / 3.71 <fastest>
    (_PICKSETTOENAMES S).....7016 / 1 <slowest>

Using my While one.



I hope you don't think I'm trying to tell you anything. I've learned so much just from looking at your posted examples.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Question about SSDel
« Reply #10 on: April 01, 2010, 04:04:05 PM »
I completely forgot about checking if the variable was valid. Thank you.
I think I'll go with this...

Code: [Select]
(defun AT:SS->List (SS VLA / l)
  (if (eq 'PICKSET (type SS))
    ((lambda (i)
       (while (setq e (ssname SS (setq i (1+ i))))
         (if VLA
           (setq l (cons (vlax-ename->vla-object e) l))
           (setq l (cons e l))
         ) ;_ if
       ) ;_ while
     ) ;_ lambda
      -1
    )
  ) ;_ if
) ;_ defun
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Question about SSDel
« Reply #11 on: April 01, 2010, 04:05:35 PM »
Code: [Select]
   (AT:SS->LIST S nil)......1890 / 3.71 <fastest>
    (_PICKSETTOENAMES S).....7016 / 1 <slowest>

cool, on quick glance I wouldn't have guessed that significant a performance difference.

I hope you don't think I'm trying to tell you anything.

The minute a man thinks he knows it all he becomes a fool, subtitle: bring it on brother, it's all good, and thanks for the edumacation.

I've learned so much just from looking at your posted examples.

Thanks for the acknowledgment Alan, nice of you to say and it takes the edge off the smashing headache I'm sporting today.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Question about SSDel
« Reply #12 on: April 01, 2010, 04:13:35 PM »
Code: [Select]
    (AT:SS->LIST S nil)......1890 / 3.71 <fastest>
    (_PICKSETTOENAMES S).....7016 / 1 <slowest>

cool, on quick glance I wouldn't have guessed that significant a performance difference.

I hope you don't think I'm trying to tell you anything.

The minute a man thinks he knows it all he becomes a fool, subtitle: bring it on brother, it's all good, and thanks for the edumacation.

I've learned so much just from looking at your posted examples.

Thanks for the acknowledgment Alan, nice of you to say and it takes the edge off the smashing headache I'm sporting today.

I was pretty surprised too.
Thanks for understanding. :)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Question about SSDel
« Reply #13 on: April 01, 2010, 04:54:50 PM »
Give this a test drive 8-)
Code: [Select]
;;  http://www.theswamp.org/index.php?topic=14184.msg171131#msg171131
(defun ss->lst (ss / i ename result)
  (and (eq 'pickset (type ss))
       (setq i -1)
       (while (setq ename (ssname ss (setq i (1+ i))))
         (setq result (cons ename result))
       )
  )
  result
)
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Question about SSDel
« Reply #14 on: April 01, 2010, 05:19:21 PM »
Give this a test drive 8-)
Code: [Select]
;;  http://www.theswamp.org/index.php?topic=14184.msg171131#msg171131
(defun ss->lst (ss / i ename result)
  (and (eq 'pickset (type ss))
       (setq i -1)
       (while (setq ename (ssname ss (setq i (1+ i))))
         (setq result (cons ename result))
       )
  )
  result
)

yep :cool:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst