Author Topic: acad_strlsort in Autocad 2011  (Read 3582 times)

0 Members and 1 Guest are viewing this topic.

hmspe

  • Bull Frog
  • Posts: 368
acad_strlsort in Autocad 2011
« on: July 15, 2010, 07:00:39 PM »
I just had the (mis)fortune on having to start running Autocad 2011.  I still use the rather ancient DDCHPROP.LSP, which is broken in 2011 because the acad_strlsort function is broken.  I've patched DDCHPROP for now by substitution the following code, but I thought I should ask if there is a better solution/replacement.   The first line in the lisp file I took this from is ";;; Michels Visual LISP Functions".  I'm not sure where or when I found it.  No copyright notice in the file.
Code: [Select]
  (defun strl_sort (f_stringlist / f_numl f_strl f_n f_cur)            ; similar to acad_strlsort, but sorts string representing numbers numberically
    (setq f_numl nil
          f_strl nil
    )
    (foreach f_n f_stringlist                                          ; loop through each element in list
      (progn
        (if (numberp (read f_n))                                       ; test if number
          (setq f_numl (append f_numl (list f_n)))                     ; create list of numbers
          (setq f_strl (append f_strl (list f_n)))                     ; create list of strings
        )
      )
    )
    (setq f_stringlist nil)
    (repeat (length f_numl)                                            ; loop through list of numbers
      (progn
        (setq f_cur (car f_numl))
        (foreach f_n (cdr f_numl)                                      ; loop through remainder of number list
          (if (> (read f_cur) (read f_n))                              ; test if current value smaller than elements in list
            (setq f_cur f_n)                                           ; if so replace current value with smaller value
          )
        )
        (setq f_numl (remove f_cur f_numl))                            ; remove current (smallest) value from number list
        (setq f_stringlist (append f_stringlist (list f_cur)))         ; add current (smallest) value to end of final list
      )
    )
    (repeat (length f_strl)                                            ; loop through list of strings
      (progn
        (setq f_cur (car f_strl))
        (foreach f_n (cdr f_strl)                                      ; loop though remainder of string list
          (if (> f_cur f_n)                                            ; test for alphabetical order
            (setq f_cur f_n)                                           ; replace current value for precending value
          )
        )
        (setq f_strl (remove f_cur f_strl))                            ; remove current value from string list
        (setq f_stringlist (append f_stringlist (list f_cur)))         ; add current value to end of final list
      )
    )
  )
  ;eg (strl_sort '("b" "a" "10" "1")) = ("1" "10" "a" "b")

  (defun remove (f_new f_newlist / f_test)                             ; removes first occurance of an element from a list
    (if (member f_new f_newlist)                                       ; is value present in list
      (progn
        (setq f_test nil)                                              ; test to see if element removed
        (repeat (length f_newlist)                                     ; loop through list
          (progn
            (if (not (and (= f_test nil) (= (car f_newlist) f_new)))       ; test if element removed or element is to be removed
              (setq f_newlist (cdr (append f_newlist (list (car f_newlist)))))  ; swaps moves first element to end of list
              (progn
                (setq f_test t)                                            ; element has been removed
                (setq f_newlist (cdr f_newlist))                           ; remove first element from list
              )
            )
          )
        )
      )
    )
  )
  ;eg (remove 1 '(1 1 2 1)) = (1 2 1)
 
"Science is the belief in the ignorance of experts." - Richard Feynman

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: acad_strlsort in Autocad 2011
« Reply #1 on: July 15, 2010, 09:45:07 PM »
More sorts. 8-)
http://www.theswamp.org/index.php?topic=16564.0

http://www.theswamp.org/index.php?topic=6474.0


I remember Lee has a sort as well but I can't put my hands on it at the moment.

PS OK here it is.
http://www.theswamp.org/index.php?topic=30262.0
« Last Edit: July 15, 2010, 09:59:02 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.

alanjt

  • Needs a day job
  • Posts: 5353
  • Standby for witty remark...
Re: acad_strlsort in Autocad 2011
« Reply #2 on: July 15, 2010, 10:11:19 PM »
Ugh, if they are going to break old LISP functions, they could at least add some new ones. :realmad:
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7535
Re: acad_strlsort in Autocad 2011
« Reply #3 on: July 15, 2010, 11:27:46 PM »
This function is not broken on my 2011?

(ACAD_STRLSORT '( "z" "a" "c" "d" "b" "1")) = ("1" "a" "b" "c" "d" "z")


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: acad_strlsort in Autocad 2011
« Reply #4 on: July 15, 2010, 11:38:38 PM »
ditto

(ACAD_STRLSORT '( "z10" "z1" "z11" "a" "01" "z" "11"  "c" "d" "b" "1"))

;;==>> ("01" "1" "11" "a" "b" "c" "d" "z" "z1" "z10" "z11")
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

hmspe

  • Bull Frog
  • Posts: 368
Re: acad_strlsort in Autocad 2011
« Reply #5 on: July 16, 2010, 12:26:32 AM »
Interesting.  I'm seeing the same general problem as posted here:  http://forums.autodesk.com/t5/AutoCAD-2011/acad-strlsort-problem-or-is-it-bigger-than-that/m-p/2667368#M796    I did not test to see exactly what was required to have acad_strlsort fail since the problem has been verified and escalated (but apparently not fixed yet).

Martin
"Science is the belief in the ignorance of experts." - Richard Feynman

hmspe

  • Bull Frog
  • Posts: 368
Re: acad_strlsort in Autocad 2011
« Reply #6 on: July 16, 2010, 09:24:50 AM »
More sorts. 8-)
Thanks for the links. 

One thing I notice is that these functions place strings starting with an underscore at the end of the list.  I know that Microsoft decided some years ago that this it the "correct" way, but I set up my file storage system under Win98, and I use a starting underscore to force "most used" folders and such to the top of a list.  Autocad appears to do the same -- "_KTI_Control" appears first in the layer manager, not last.  I'm not sure what acad_strlsort does when it's working.  My A2010 will not reinstall due to a damaged key in the registry so I can't check at this point.  If Autodesk tech support suggests removing and reinstalling be very, very cautious....

Martin
"Science is the belief in the ignorance of experts." - Richard Feynman

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: acad_strlsort in Autocad 2011
« Reply #7 on: July 16, 2010, 10:57:07 AM »
My TabSort puts underscore after numbers & before letters.
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.

hmspe

  • Bull Frog
  • Posts: 368
Re: acad_strlsort in Autocad 2011
« Reply #8 on: July 16, 2010, 12:10:05 PM »
My TabSort puts underscore after numbers & before letters.

My apologies.  I think I tested 3 or 4 functions and was seeing essentially the same results, so I jumped to an incorrect conclusion.  I'll plead late night and testing on a laptop while watching the evening news.  :roll:
"Science is the belief in the ignorance of experts." - Richard Feynman

Lee Mac

  • Seagull
  • Posts: 12937
  • London, England
Re: acad_strlsort in Autocad 2011
« Reply #9 on: July 16, 2010, 08:10:07 PM »
If all else fails would this produce the same result?

Code: [Select]
(vl-sort <list> '<)
I'm guessing it just goes on the ASCII codes but is that the order that acad_strlsort works to?

Lee Mac

  • Seagull
  • Posts: 12937
  • London, England
Re: acad_strlsort in Autocad 2011
« Reply #10 on: July 16, 2010, 08:11:30 PM »
Answered my own question...

Code: [Select]
Command: (vl-sort '("a" "d" "A" "D" "1" "-" "_") '<)
("-" "1" "A" "D" "_" "a" "d")

Command: (acad_strlsort '("a" "d" "A" "D" "1" "-" "_"))
("-" "_" "1" "a" "A" "d" "D")