TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: hmspe 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.
(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)
-
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
-
Ugh, if they are going to break old LISP functions, they could at least add some new ones. :realmad:
-
This function is not broken on my 2011?
(ACAD_STRLSORT '( "z" "a" "c" "d" "b" "1")) = ("1" "a" "b" "c" "d" "z")
-
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")
-
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
-
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
-
My TabSort puts underscore after numbers & before letters.
-
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:
-
If all else fails would this produce the same result?
(vl-sort <list> '<)
I'm guessing it just goes on the ASCII codes but is that the order that acad_strlsort works to?
-
Answered my own question...
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")