Sort SS based on creation order

Discussion in 'AutoCAD' started by Don Butler, Jul 6, 2004.

  1. Don Butler

    Don Butler Guest

    Does anyone know a way to take a list of object handles and sort them by
    their HEX value?

    The final list would be then sorted from oldest to newest object.

    Thanks,

    Don
     
    Don Butler, Jul 6, 2004
    #1
  2. Don Butler

    Jürg Menzi Guest

    Hi Don

    AFAIK a selection set reflects the creation order...

    Cheers
     
    Jürg Menzi, Jul 6, 2004
    #2
  3. Don Butler

    Jeff Mishler Guest

    Except when you manually select the objects, or use more than 1
    window/crossing.....

    and even if you do select them by window, crossing or All, the order is
    reversed.....first item in ss is the last one created.

    Jeff
     
    Jeff Mishler, Jul 6, 2004
    #3
  4. Don Butler

    Don Butler Guest

    I'm very sorry, but I forgot to update the message header after I changed
    the body of the message.

    I am trying to sort a list of entity handles.

    1. Select objects
    2. Extract handles into a list.
    3. Sort the list from lowest number to highest number based on handle
    value.
    4. Create new SS and SSADD each entity in correct order.

    Another option is to bypass creating a new SS and modify the selected
    objects based only on the sorted list.

    I assume the key is to convert the handle to a number that can be sorted.

    Thanks,

    Don
     
    Don Butler, Jul 6, 2004
    #4
  5. Seems that (acad_strlsort) can handle the sorting.
     
    Jason Piercey, Jul 6, 2004
    #5
  6. Don Butler

    ECCAD Guest

    Maybe I'm wrong, but couldn't you just do:
    (setq ss (ssget "X"))
    and sift through each entity, make a 'list' of the handles,
    then merely 'reverse' the list ?

    Bob
     
    ECCAD, Jul 6, 2004
    #6
  7. Don Butler

    Don Butler Guest

    What I'm trying to do is...

    The user places callout tags programmatically for a bill of materials.

    Later he numbers the tags in a logical sequence to coincide with the order
    of fabrication.

    I want to also give him the option to quickly number the tags in the order
    the tags were created.

    He would window the tags and they would be numbered thusly.

    Don
     
    Don Butler, Jul 6, 2004
    #7
  8. Don Butler

    Don Butler Guest

    Are all handles able to be sorted this way regardless of the size of the
    drawing?

    Would they indicate the order of creation?

    Seem pretty simple.

    Thanks,

    Don
     
    Don Butler, Jul 6, 2004
    #8
  9. I can't think of anything that would indicate
    otherwise. Someone please correct me if
    I am wrong
     
    Jason Piercey, Jul 6, 2004
    #9
  10. Don Butler

    Don Butler Guest

    So I guess Handles can always be sorted based on their interpreted values
    via VL-SORT-I.

    I'm sorry I'm so dense at this. I don't know anything about HEX
    representations.

    I appreciate your help.

    Don
     
    Don Butler, Jul 6, 2004
    #10
  11. Don Butler

    Don Butler Guest

    Wow, that would be too easy! I'm going to experiment.

    Thanks,

    Don
     
    Don Butler, Jul 6, 2004
    #11
  12. Don Butler

    Don Butler Guest

    Yes, I've tried too. Amazingly simple.

    Don

     
    Don Butler, Jul 6, 2004
    #12
  13. Don Butler

    Don Butler Guest

    wE cAn't bE tHaT CrItiCaL !

    :)

    Don


     
    Don Butler, Jul 6, 2004
    #13
  14. Tony Tanzillo, Jul 7, 2004
    #14
  15. Don Butler

    Viliam Guest

    It is my understanding that the entity handles are being reused by acad.
    the order of handless DOES NOT represent the order of creation. I do
    remember this from one of your posts, Tony. I just can't remember more
    details about it. Bottom line for me is that handles do not represent
    the history!

    Viliam
     
    Viliam, Jul 7, 2004
    #15
  16. Viliam - The reason you can't sort handles without some
    extra work, is because handles are returned as strings,
    which means that they're treated as strings by the >
    or < functions:

    "FF" = 255

    "AAA" = 2730

    Command: (> "AAA" "FF")
    nil

    Since not all handles have the same string width, or
    number of hexadecimal digits, the strings must be
    left-padded with 0's or spaces, or it is not a numeric
    comparision.
     
    Tony Tanzillo, Jul 7, 2004
    #16
  17. Don Butler

    Doug Broad Guest

    Excellent points.

    If the handles are not reused (I doubt they are),
    it might be possible to use

    ;;Conversion from hexadecimal to decimal
    ;;Assumes hexadecimal notation is upper case.
    ;;Returns real decimal number
    (defun Hex2Dec (str / sum)
    ;;D.C.Broad
    (setq sum 0)
    (foreach n (vl-string->list str)
    (setq n (IF (< n 65) (- n 48)(- n 55)))
    (setq sum (+ n (* sum 16.0))))
    sum)

    (vl-sort-i (mapcar 'hex2dec handlelist) '<)

    to get an indexed list of the correct entity order.

    Of course it might be easier to just parse the
    entities in the drawing with entnext and see
    if its associated handle is in the list.
     
    Doug Broad, Jul 7, 2004
    #17
  18. Don Butler

    Don Butler Guest

    Thanks for the link.

    Don

     
    Don Butler, Jul 7, 2004
    #18
  19. Don Butler

    Don Butler Guest

    Tony,

    Two questions...

    1. Do you know if entity handles are ever re-used? I.E. an entity was
    deleted from the drawing database.
    2. Do they represent the sequential order of creation? If not, is there
    another way to determine the order?

    It was my understanding that 1=NO and 2=YES

    Thanks

    Don
     
    Don Butler, Jul 7, 2004
    #19
  20. Don Butler

    Don Butler Guest

    Thanks Doug

    Don

     
    Don Butler, Jul 7, 2004
    #20
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.