Author Topic: Question about SSDel  (Read 5114 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

LE3

  • Guest
Re: Question about SSDel
« Reply #15 on: April 01, 2010, 05:44:20 PM »
by looking into the last two post... it took me way back to the x-arch or reni urban place, because of the code style - ish :)

when I was like 4 or 7 years  :lol:  :-P

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Question about SSDel
« Reply #16 on: April 01, 2010, 05:49:32 PM »
Ah yes, the good old daze when Tony would publicly, and gratuitously insult Reini, calling him a fool etc. I also remember coming to your defense several times when you were in his sights. Of course, Tony and I got along famously, almost as well as I got on with Frank Oquendo.  :whistle:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

LE3

  • Guest
Re: Question about SSDel
« Reply #17 on: April 01, 2010, 05:57:48 PM »
Ah yes, the good old daze when Tony would publicly, and gratuitously insult Reini, calling him a fool etc. I also remember coming to your defense several times when you were in his sights. Of course, Tony and I got along famously, almost as well as I got on with Frank Oquendo.  :whistle:

any idea of what happen to Frank Oquendo?


and yes the friendly days.... :)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Question about SSDel
« Reply #18 on: April 01, 2010, 05:59:34 PM »
Don't have a clue, I always assumed he legally changed his name because he appeared to vanish. Maybe Bobby Jones (who occasionally hangs here) knows, they were once business partners of sorts.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Question about SSDel
« Reply #19 on: April 01, 2010, 06:08:35 PM »
Spider senses are tingling, here comes Bobby now!
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Question about SSDel
« Reply #20 on: April 01, 2010, 06:10:35 PM »
Don't have a clue, I always assumed he legally changed his name because he appeared to vanish. Maybe Bobby Jones (who occasionally hangs here) knows, they were once business partners of sorts.

I hang when possible, I lurk even more, and I try to refrain from trolling as much as possible.

I haven't heard from Frank in a long while.  I miss those good 'ol days too :)
Bobby C. Jones

LE3

  • Guest
Re: Question about SSDel
« Reply #21 on: April 01, 2010, 06:11:21 PM »
Spider senses are tingling, here comes Bobby now!

:)


Also, about Robert Bell.... or maybe he is in the ng's still - but I do not frequent there as I use to....

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Question about SSDel
« Reply #22 on: April 01, 2010, 06:11:49 PM »
Spider senses are tingling, here comes Bobby now!

That's amazing :)
Bobby C. Jones

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Question about SSDel
« Reply #23 on: April 01, 2010, 06:13:09 PM »
Spider senses are tingling, here comes Bobby now!

:)


Also, about Robert Bell.... or maybe he is in the ng's still - but I do not frequent there as I use to....

Bob hangs a lot in the AUGI groups.  I would visit there more often, but I don't like the UI as much as the swamp.
Bobby C. Jones

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Question about SSDel
« Reply #24 on: April 01, 2010, 06:20:42 PM »
I hang when possible, I lurk even more, and I try to refrain from trolling as much as possible.

I haven't heard from Frank in a long while.  I miss those good 'ol days too :)

evidently :)

Also, about Robert Bell.... or maybe he is in the ng's still - but I do not frequent there as I use to....

once I found the swamp I basically dropped the audesk ngs

That's amazing :)

the powers come and go, if only I could harness them on demand

Also, about Robert Bell.... or maybe he is in the ng's still - but I do not frequent there as I use to....

augi sucks on so many levels :ugly:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Question about SSDel
« Reply #25 on: April 01, 2010, 07:15:17 PM »
If you really wanted to use recursion, perhaps

Code: [Select]
(defun ss->lst (ss / f)

  (defun f (i / e)
    (if (<= 0 i)
      (cons (ssname ss i) (f (1- i)))))

  (f (1- (sslength ss))))

But its not really worth it imo, considering the unpredictable sizes of SelSets coupled with the performance deficits of recursive iteration.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Question about SSDel
« Reply #26 on: April 01, 2010, 07:48:57 PM »
If you really wanted to use recursion, perhaps

Code: [Select]
(defun ss->lst (ss / f)

  (defun f (i / e)
    (if (<= 0 i)
      (cons (ssname ss i) (f (1- i)))))

  (f (1- (sslength ss))))

But its not really worth it imo, considering the unpredictable sizes of SelSets coupled with the performance deficits of recursive iteration.

Nice.

You're probably right. I was more curious than anything.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Question about SSDel
« Reply #27 on: April 01, 2010, 08:05:09 PM »
Counterpart:

Code: [Select]
;;; Convert list of ename objects to 1 selection set
;;; L - list of enames
;;; Alan J. Thompson, 04.01.10
(defun AT:List->SS (L)
  (if (cdr L)
    (ssadd (car L) (AT:List->SS (cdr L)))
    (ssadd (car L))
  ) ;_ if
) ;_ defun
« Last Edit: April 03, 2010, 09:29:16 AM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox