How to create list from ssget

Discussion in 'AutoCAD' started by Adesu, Nov 4, 2004.

  1. Adesu

    Adesu Guest

    _$ (setq ss (ssget ))
    <Selection set: 7eb>

    _$ (setq ss1 (sslength ss ))
    1

    _$(setq list_ss (xxxx xxxx xxxx))
    (1 2 3 4 5 6 etc)

    I mean and I would to create a list as (1 2 3 4 5 6 etc),is it posible to
    create it,anybody to know?,thanks.
     
    Adesu, Nov 4, 2004
    #1
  2. Adesu

    James Allen Guest

    Hi Adesu, have you already noticed the ssname function? I use ssname in a
    repeat loop to do this. Is that enough to get you there?
     
    James Allen, Nov 4, 2004
    #2
  3. Adesu

    Don Butler Guest

    This is what I use to build a list of Enames or VLA-Objects from a SS.

    (defun bpc:ss->list (ss / i lis)
    (repeat (setq i (sslength ss))
    (setq i (1- i)
    lis (cons (ssname ss i) lis)
    )
    )
    )
    (defun bpc:ss->objlist (ss / i lis)
    (repeat (setq i (sslength ss))
    (setq i (1- i)
    lis (cons (vlax-ename->vla-object (ssname ss i)) lis)
    )
    )
    )

    (bpc:ss->list ss)
    (<Entity name: 7edaced8> <Entity name: 7edaceb8> <Entity name: 7edacec0>
    <Entity name: 7edad038>)

    Don
     
    Don Butler, Nov 4, 2004
    #3
  4. Adesu

    Adesu Guest

    Hi Don, this code I looking for,thanks a lot

     
    Adesu, Nov 5, 2004
    #4
  5. Adesu

    Adesu Guest

    Hi Don,
    Code from you I create become simple, in order to easy to learn,here this
    below

    (setq ss (ssget))
    (setq i (sslength ss))
    (setq i (1- i))
    (setq lis (cons (ssname ss i) lis))
    (setq table (bpc:ss->list ss))
    (setq ent1 (nth 0 table))
    (setq ent2 (nth 1 table))
    (setq ent3 (nth 2 table))
    (setq ent4 (nth 3 table))
    (setq ent5 (nth 4 table))
    (setq ent6 (nth 5 table))
    (setq ent7 (nth 6 table))

    $ (setq ss (ssget))
    (setq i (sslength ss))
    (setq i (1- i))
    (setq lis (cons (ssname ss i) lis))
    (setq table (bpc:ss->list ss))
    (setq ent1 (nth 0 table))
    (setq ent2 (nth 1 table))
    (setq ent3 (nth 2 table))
    (setq ent4 (nth 3 table))
    (setq ent5 (nth 4 table))
    (setq ent6 (nth 5 table))
    (setq ent7 (nth 6 table))
    <Selection set: 1a>
    6
    5
    (<Entity name: 14c4238> <Entity name: 14c4268> <Entity name: 14c4268>
    <Entity name: 14c41a0> <Entity name: 14c41a0> <Entity name: 14c41a0> . 21)
    (<Entity name: 14c4250> <Entity name: 14c4240> <Entity name: 14c4260>
    <Entity name: 14c4258> <Entity name: 14c4248> <Entity name: 14c4238>)
    <Entity name: 14c4250>
    <Entity name: 14c4240>
    <Entity name: 14c4260>
    <Entity name: 14c4258>
    <Entity name: 14c4248>
    <Entity name: 14c4238>
    nil
    _$

    Now my question is where you find "bpc:ss->",and if this statement we change
    with others string,this program can't work,would you explain to me.thanks.
     
    Adesu, Nov 5, 2004
    #5
  6. Adesu

    Adesu Guest

    Hi James,I still confuse if a program contained "formula",like this

    [code fron Don Butler <>]
    (defun bpc:ss->list (ss / i lis)
    (repeat (setq i (sslength ss))
    (setq i (1- i)
    lis (cons (ssname ss i) lis)
    )
    )
    )
    (bpc:ss->list ss)

    I though someone create alone formula, to completed it program,I am not yet
    understanding how to build that as like Don ,now I start to more learn about
    "repeat",repeat is simple procedure,but if it combine with others var,it is
    become confuse to me.
     
    Adesu, Nov 5, 2004
    #6
  7. Adesu

    LUCAS Guest

    (defun BPC:SS->LIST (SS / I LIS) ;you can change the program name
    (repeat (setq I (sslength SS))
    (setq I (1- I)
    LIS (cons (ssname SS I) LIS)
    )
    )
    )

    (defun OKOK (SS / I LIS)
    (repeat (setq I (sslength SS))
    (setq I (1- I)
    LIS (cons (ssname SS I) LIS)
    )
    )
    )

    ;;(okok (ssget)) = (bpc:cc->list(ssget))
     
    LUCAS, Nov 5, 2004
    #7
  8. Adesu

    Adesu Guest

    Hi LUCAS,thanks a lot for your comment,oh .... yes the object able change by
    anything as like user
     
    Adesu, Nov 5, 2004
    #8
  9. Adesu

    Alaspher Guest

    Try it:
    (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex (ssget))))
     
    Alaspher, Nov 5, 2004
    #9
  10. Adesu

    Don Butler Guest

    Interesting approach...

    Don

     
    Don Butler, Nov 5, 2004
    #10
  11. Adesu

    Don Butler Guest

    or I guess...

    (vl-remove-if-not
    (function atom)
    (mapcar (function cadr) (ssnamex ss))
    )

    and...

    (mapcar (function vlax-ename->vla-object)
    (vl-remove-if-not
    (function atom)
    (mapcar (function cadr) (ssnamex ss))
    )
    )

    Maybe someone can clock the various options.

    Don
     
    Don Butler, Nov 5, 2004
    #11
  12. Adesu

    Adesu Guest

    Hi Alaspher,good idea and thanks a lot
     
    Adesu, Nov 8, 2004
    #12
  13. Adesu

    Adesu Guest

    Hi Don , and thanks to Alls participant,I 've got a lot formula to take
    added value,like this

    ; Model 1
    ; by Don Butler <>]
    (setq ss (ssget))
    (setq i (sslength ss))
    (setq i (1- i))
    (setq lis (cons (ssname ss i) lis))
    (setq table (bpc:ss->list ss))
    (setq ent1 (nth 0 table))
    (setq ent2 (nth 1 table))
    (setq ent3 (nth 2 table))
    (setq ent4 (nth 3 table))
    (setq ent5 (nth 4 table))
    (setq ent6 (nth 5 table))
    (setq ent7 (nth 6 table))


    ; Model 2
    ; by Alaspher <>
    (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex (ssget))))


    ; Model 3
    ; by Alaspher <>
    (setq ss (ssget))
    (setq ss1 (ssnamex ss))
    (setq ss2 (mapcar (function cadr) ss1))
    (setq lis (length ss2))
    (setq name1 (nth 0 ss2))
    (setq name1_data (entget name1))

    ; Model 4
    ; by Don Butler <>
    (vl-remove-if-not
    (function atom)
    (mapcar (function cadr) (ssnamex ss))
    )
     
    Adesu, Nov 8, 2004
    #13
  14. Adesu

    CAB2k Guest

    Here are the times for each & some other methods.

    ;; return a list of enames from selection set
    (defun ss->lst1 ( / idx lst);(ss / idx lst)
    (setq idx (sslength ss)
    lst (list)
    )
    (while (>= (setq idx (1- idx)) 0)
    (setq lst (cons (ssname ss idx) lst))
    )
    )

    ;;==========================================

    ; Model 2
    ; by Alaspher <>
    (defun ss->lst2 ()
    (vl-remove-if
    (function listp)
    (mapcar (function cadr)
    (ssnamex ss)))
    )

    ; Model 3
    ; by Alaspher <>
    (defun ss->lst3 ()
    (mapcar (function cadr) (ssnamex ss))
    )


    ; Model 4
    ; by Don Butler <>
    (defun ss->lst4 ()
    (vl-remove-if-not
    (function atom)
    (mapcar (function cadr) (ssnamex ss))
    )
    )


    (defun ss->lst5 (/ i lis);(ss / i lis)
    (repeat (setq i (sslength ss))
    (setq i (1- i)
    lis (cons (ssname ss i) lis)
    )
    )
    lis
    )


    (defun ss->lst6 (/ index lst)
    (setq index 0)
    (repeat (sslength ss))
    (setq lst (cons (ssname ss index) lst))
    ;;add your code here
    (setq index (1+ index))
    lst
    )


    (defun ss->lst7 (/ lst en)
    ;(setq lst '())
    (repeat (sslength ss)
    (setq lst (cons (setq en(ssname ss 0))))
    (ssdel en ss)
    )
    lst
    )


    (defun ss->lst8 (/ i ename result)
    (repeat (setq i (sslength ss))
    (setq result
    (cons
    (setq ename (ssname ss (setq i (1- i))))
    result
    )
    )
    )
    result
    )

    (defun c:test()
    ;(setq ss (ssget))
    (bench 'ss->lst1 5000)
    (bench 'ss->lst2 5000)
    (bench 'ss->lst3 5000)
    (bench 'ss->lst4 5000)
    (bench 'ss->lst5 5000)
    (bench 'ss->lst6 5000)
    (bench 'ss->lst7 5000)
    (bench 'ss->lst8 5000)
    (princ)
    )

    ;|
    Command: test

    Function: SS->LST1
    Iterations: 5000
    Timings in milliseconds
    Max: 10.0181
    Min: 0.0000
    Mean: 0.0100
    Variance: 0.0998
    Std Dev: 0.3159

    Function: SS->LST2
    Iterations: 5000
    Timings in milliseconds
    Max: 10.0181
    Min: 0.0000
    Mean: 0.0280
    Variance: 0.2793
    Std Dev: 0.5285

    Function: SS->LST3
    Iterations: 5000
    Timings in milliseconds
    Max: 10.0181
    Min: 0.0000
    Mean: 0.0240
    Variance: 0.2395
    Std Dev: 0.4894

    Function: SS->LST4
    Iterations: 5000
    Timings in milliseconds
    Max: 10.9836
    Min: 0.0000
    Mean: 0.0202
    Variance: 0.2036
    Std Dev: 0.4512

    Function: SS->LST5
    Iterations: 5000
    Timings in milliseconds
    Max: 10.0181
    Min: 0.0000
    Mean: 0.0160
    Variance: 0.1597
    Std Dev: 0.3996

    Function: SS->LST6
    Iterations: 5000
    Timings in milliseconds
    Max: 10.0181
    Min: 0.0000
    Mean: 0.0180
    Variance: 0.1798
    Std Dev: 0.4241

    Function: SS->LST7
    Iterations: 5000
    Timings in milliseconds
    Max: 10.0181
    Min: 0.0000
    Mean: 0.0160
    Variance: 0.1598
    Std Dev: 0.3998

    Function: SS->LST8
    Iterations: 5000
    Timings in milliseconds
    Max: 10.0181
    Min: 0.0000
    Mean: 0.0200
    Variance: 0.1997
    Std Dev: 0.4469
    |;
     
    CAB2k, Nov 8, 2004
    #14
  15. Adesu

    Alaspher Guest

    Bad testing because impossible results!

    "ss->lst4" is faster then "ss->lst3"... - it's impossible! You see?

    "ss->lst6" in your code contain ERROR, must be:

    (defun ss->lst6 (ss / index lst)
    (setq index 0)
    (repeat (sslength ss) (setq lst (cons (ssname ss index) lst)) (setq index (1+ index)))
    lst
    )

    "ss->lst7" can't be tested in iteration mode, because after first iteration selection set will be empty!

    (defun ss->lst7 (ss / lst en)
    (repeat (sslength ss) (setq lst (cons (setq en (ssname ss 0)) lst)) (ssdel en ss))
    lst
    )

    There is right testing results:

    function | min | max | aver | percent | comment
    ---------+----------+----------+----------+----------+---------
    ss->lst1 | 00:00.36 | 00:00.37 | 00:00.36 | 113% |
    ss->lst2 | 00:08.38 | 00:08.47 | 00:08.44 | 2 638% |
    ss->lst3 | 00:08.34 | 00:08.36 | 00:08.35 | 2 609% | only for "X" selection
    ss->lst4 | 00:08.44 | 00:08.46 | 00:08.45 | 2 640% |
    ss->lst5 | 00:00.36 | 00:00.38 | 00:00.37 | 116% |
    ss->lst6 | 00:00.35 | 00:00.36 | 00:00.36 | 113% |
    ss->lst7 | 14:27.96 | N/A | 14:27.96 | 271 238% | tested last, only 1 exec
    ss->lst8 | 00:00.37 | 00:00.37 | 00:00.37 | 116% |
    ss->lst9 | 00:00.32 | 00:00.32 | 00:00.32 | 100% | best time
    ss->lst0 | 00:00.52 | 00:00.54 | 00:00.53 | 166% | may be slowly in the first exec

    * Test conditions comments:
    - only compiled function testing;
    - only one iteration (because "ss->lst7");
    - 250 000 entities in selection set;
    - full regeneration before test;
    - first bare testing for all function, except "ss->lst7";
    - 3 work evaluations, except "ss->lst7".

    Addition functions:

    (defun ss->lst9 (ss / i ename result)
    (setq i -1)
    (while (setq ename (ssname ss (setq i (1+ i)))) (setq result (cons ename result)))
    )

    (defun ss->lst0 (ss)
    (defun _ss->lst0 (i / _ent)
    (if (setq _ent (ssname ss i))
    (cons _ent (_ss->lst0 (1+ i)))
    )
    )
    (_ss->lst0 0)
    )
     
    Alaspher, Nov 8, 2004
    #15
  16. Adesu

    CAB2k Guest

    Thanks for correcting my errors.
    And for the other methods.
     
    CAB2k, Nov 8, 2004
    #16
  17. Adesu

    Adesu Guest

    Hi Alaspher,
    wow .......how tested this program !

    iteration selection set will be empty!
     
    Adesu, Nov 9, 2004
    #17
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.