<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888691#M164282</link>
    <description>This may not necessarily produce the desired result. If the drawing contained&lt;BR /&gt;
layers 0, 9 and 10, the code would return:&lt;BR /&gt;
&lt;BR /&gt;
("0","10","9")&lt;BR /&gt;
&lt;BR /&gt;
If you are certain that the layers will always be numbers, you should use&lt;BR /&gt;
(atoi) to convert the names to a list of numbers, sort them and then use&lt;BR /&gt;
(itoa) to convert back to strings.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
Andrew Wilford</description>
    <pubDate>Tue, 21 Sep 1999 18:17:09 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>1999-09-21T18:17:09Z</dc:date>
    <item>
      <title>How to sort a string</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888689#M164280</link>
      <description>I am doing a tblsearch to collect layer names (which are sheet numbers)&lt;BR /&gt;
that I wish to display. However, the layer table is apparently not in&lt;BR /&gt;
alphanumeric order so I get a display like 1,2,3,4,6,9,10,5. This string&lt;BR /&gt;
has been constructed with strcat and is saved as a variable. How can I&lt;BR /&gt;
sort the contents of the variable so it would display as&lt;BR /&gt;
1,2,3,4,5,6,9,10.&lt;BR /&gt;
&lt;BR /&gt;
TIA,&lt;BR /&gt;
Cliff</description>
      <pubDate>Tue, 21 Sep 1999 17:46:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888689#M164280</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>1999-09-21T17:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888690#M164281</link>
      <description>Use the (acad_strlsort) function.&lt;BR /&gt;
&lt;BR /&gt;
See following example:&lt;BR /&gt;
&lt;BR /&gt;
(setq h nil)&lt;BR /&gt;
(setq a (cdr (assoc 2 (tblnext "layer" "T"))))&lt;BR /&gt;
(setq h (append h (list a)))&lt;BR /&gt;
(while (setq a (cdr (assoc 2 (tblnext "layer"))))&lt;BR /&gt;
 (setq h (append h (list a)))&lt;BR /&gt;
)&lt;BR /&gt;
(setq h (acad_strlsort h))&lt;BR /&gt;
&lt;BR /&gt;
R.K. McSwain&lt;BR /&gt;
mcswain@maysvilleky.net&lt;BR /&gt;
&lt;BR /&gt;
Cliff DuHaime &lt;CST&gt; wrote in message&lt;BR /&gt;
news:37E7C480.2768BD44@megahits.com...&lt;BR /&gt;
&amp;gt; I am doing a tblsearch to collect layer names (which are sheet numbers)&lt;BR /&gt;
&amp;gt; that I wish to display. However, the layer table is apparently not in&lt;BR /&gt;
&amp;gt; alphanumeric order so I get a display like 1,2,3,4,6,9,10,5. This string&lt;BR /&gt;
&amp;gt; has been constructed with strcat and is saved as a variable. How can I&lt;BR /&gt;
&amp;gt; sort the contents of the variable so it would display as&lt;BR /&gt;
&amp;gt; 1,2,3,4,5,6,9,10.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; TIA,&lt;BR /&gt;
&amp;gt; Cliff&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/CST&gt;</description>
      <pubDate>Tue, 21 Sep 1999 18:13:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888690#M164281</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>1999-09-21T18:13:15Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888691#M164282</link>
      <description>This may not necessarily produce the desired result. If the drawing contained&lt;BR /&gt;
layers 0, 9 and 10, the code would return:&lt;BR /&gt;
&lt;BR /&gt;
("0","10","9")&lt;BR /&gt;
&lt;BR /&gt;
If you are certain that the layers will always be numbers, you should use&lt;BR /&gt;
(atoi) to convert the names to a list of numbers, sort them and then use&lt;BR /&gt;
(itoa) to convert back to strings.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
Andrew Wilford</description>
      <pubDate>Tue, 21 Sep 1999 18:17:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888691#M164282</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>1999-09-21T18:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888692#M164283</link>
      <description>Cliff,&lt;BR /&gt;
&lt;BR /&gt;
I addition to using (acad_strlsort) as R.K. suggested, a function to append&lt;BR /&gt;
leading zeros to the number strings will produce the desired results. Here's&lt;BR /&gt;
the Function:&lt;BR /&gt;
&lt;BR /&gt;
;; ----- (lead-zeros [No of Digits][String]) ------------&lt;BR /&gt;
;; Given a Numeric String and Total number of Digits, This Function&lt;BR /&gt;
;; Returns a String With the Correct Amount of Leading Zeros.&lt;BR /&gt;
(defun lead-zeros (digits str / cnt done z-str)&lt;BR /&gt;
 (setq cnt 1 z-str "" done nil)&lt;BR /&gt;
 (repeat digits&lt;BR /&gt;
  (if (and (= (strlen str) cnt)(= done nil))&lt;BR /&gt;
   (progn&lt;BR /&gt;
    (if (/= cnt digits)&lt;BR /&gt;
     (repeat (- digits cnt)(setq z-str (strcat "0" z-str)))&lt;BR /&gt;
    )&lt;BR /&gt;
    (setq str (strcat z-str str))&lt;BR /&gt;
    (setq done T)&lt;BR /&gt;
   )&lt;BR /&gt;
  )&lt;BR /&gt;
  (setq z-str "" cnt (1+ cnt))&lt;BR /&gt;
 )&lt;BR /&gt;
 str&lt;BR /&gt;
);; End Function (lead-zeros)&lt;BR /&gt;
&lt;BR /&gt;
Apply this within a loop to rebuild a new list of strings containing the&lt;BR /&gt;
leading zeros, then use (acad_strlsort) on the rebuilt list.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
--&lt;BR /&gt;
Phillip Kenewell&lt;BR /&gt;
CAD Systems Technician&lt;BR /&gt;
Air Gage Company&lt;BR /&gt;
pkenewell@airgage.com&lt;BR /&gt;
&lt;BR /&gt;
Cliff DuHaime &lt;CST&gt; wrote in message&lt;BR /&gt;
news:37E7C480.2768BD44@megahits.com...&lt;BR /&gt;
&amp;gt; I am doing a tblsearch to collect layer names (which are sheet numbers)&lt;BR /&gt;
&amp;gt; that I wish to display. However, the layer table is apparently not in&lt;BR /&gt;
&amp;gt; alphanumeric order so I get a display like 1,2,3,4,6,9,10,5. This string&lt;BR /&gt;
&amp;gt; has been constructed with strcat and is saved as a variable. How can I&lt;BR /&gt;
&amp;gt; sort the contents of the variable so it would display as&lt;BR /&gt;
&amp;gt; 1,2,3,4,5,6,9,10.&lt;/CST&gt;</description>
      <pubDate>Tue, 21 Sep 1999 20:26:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888692#M164283</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>1999-09-21T20:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888693#M164284</link>
      <description>The following function will sort a list of strings, sorting string&lt;BR /&gt;
representations of integers as you wish, alpha strings normally.&lt;BR /&gt;
&lt;BR /&gt;
e.g.&lt;BR /&gt;
&lt;BR /&gt;
(sort_strs '("19" "0" "9" "6" "11" "1"))&lt;BR /&gt;
&lt;BR /&gt;
will return ("0" "1" "6" "9" "11" "19")&lt;BR /&gt;
&lt;BR /&gt;
(defun sort_strs (strs / len x y i j)&lt;BR /&gt;
  (cond&lt;BR /&gt;
    ( acad_strlsort&lt;BR /&gt;
      (setq len 0)&lt;BR /&gt;
      (foreach x strs (setq len (max (strlen x) len)))&lt;BR /&gt;
      (mapcar&lt;BR /&gt;
       '(lambda (y)&lt;BR /&gt;
          (while (and (&amp;lt; (setq j (ascii y)) 33) (&amp;lt; 0 j))&lt;BR /&gt;
            (setq y (substr y 2))&lt;BR /&gt;
          )&lt;BR /&gt;
          y&lt;BR /&gt;
        )&lt;BR /&gt;
        (acad_strlsort&lt;BR /&gt;
          (mapcar&lt;BR /&gt;
           '(lambda (x)&lt;BR /&gt;
              (if (and (&amp;lt; (setq i (ascii x)) 58) (&amp;lt; 47 i))&lt;BR /&gt;
                (repeat (- len (strlen x)) (setq x (strcat " " x)))&lt;BR /&gt;
              )&lt;BR /&gt;
              x&lt;BR /&gt;
            )&lt;BR /&gt;
            strs&lt;BR /&gt;
          )&lt;BR /&gt;
        )&lt;BR /&gt;
      )&lt;BR /&gt;
    )&lt;BR /&gt;
    ( t  (princ "\nDoh! &lt;ACAD_STRLSORT&gt; function is unavailable.") strs )&lt;BR /&gt;
  )&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
Throwing it inside a wrapper to return a sorted list of layers in the&lt;BR /&gt;
drawing:&lt;BR /&gt;
&lt;BR /&gt;
(defun get_layers ( / d r)&lt;BR /&gt;
  (while (setq d (tblnext "layer" (null d)))&lt;BR /&gt;
    (setq r (cons (cdr (assoc 2 d)) r))&lt;BR /&gt;
  )&lt;BR /&gt;
  (sort_strs r)&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
I have another routine to sort integers; let me know if you'd like it.&lt;BR /&gt;
&lt;BR /&gt;
Cheers.&lt;BR /&gt;
&lt;BR /&gt;
______________________________&lt;BR /&gt;
&lt;BR /&gt;
puckettm@bantrel.com&lt;BR /&gt;
Not a Member of the AutoDESK&lt;BR /&gt;
Discussion Forum Moderator Program&lt;BR /&gt;
Imagination makes all things possible&lt;BR /&gt;
______________________________&lt;BR /&gt;
&lt;BR /&gt;
Cliff DuHaime &lt;CST&gt; wrote in message&lt;BR /&gt;
news:37E7C480.2768BD44@megahits.com...&lt;BR /&gt;
I am doing a tblsearch to collect layer names (which are sheet numbers)&lt;BR /&gt;
that I wish to display. However, the layer table is apparently not in&lt;BR /&gt;
alphanumeric order so I get a display like 1,2,3,4,6,9,10,5. This string&lt;BR /&gt;
has been constructed with strcat and is saved as a variable. How can I&lt;BR /&gt;
sort the contents of the variable so it would display as&lt;BR /&gt;
1,2,3,4,5,6,9,10.&lt;BR /&gt;
&lt;BR /&gt;
TIA,&lt;BR /&gt;
Cliff&lt;/CST&gt;&lt;/ACAD_STRLSORT&gt;</description>
      <pubDate>Tue, 21 Sep 1999 20:35:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888693#M164284</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>1999-09-21T20:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888694#M164285</link>
      <description>Wow, what a response! This will take some time to sort out &lt;G&gt;. Thanks&lt;BR /&gt;
everyone, I'll let you know how I make out.&lt;BR /&gt;
&lt;BR /&gt;
Cliff&lt;/G&gt;</description>
      <pubDate>Tue, 21 Sep 1999 22:54:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888694#M164285</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>1999-09-21T22:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888695#M164286</link>
      <description>(strlgather (vmergesort (strtok STRNG ",") atoi) ",")&lt;BR /&gt;
using functions from my site. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Point being, it's good to develop some library&lt;BR /&gt;
functions for common tasks.&lt;BR /&gt;
&lt;BR /&gt;
{{in English the code means -- break the string down&lt;BR /&gt;
to pieces by comma, then sort by atoi function, then&lt;BR /&gt;
glue'em back with commas again. }}&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
&lt;BR /&gt;
On Tue, 21 Sep 1999 13:46:40 -0400, Cliff DuHaime &lt;CST&gt;&lt;BR /&gt;
wrote:&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;I am doing a tblsearch to collect layer names (which are sheet numbers)&lt;BR /&gt;
&amp;gt;that I wish to display. However, the layer table is apparently not in&lt;BR /&gt;
&amp;gt;alphanumeric order so I get a display like 1,2,3,4,6,9,10,5. This string&lt;BR /&gt;
&amp;gt;has been constructed with strcat and is saved as a variable. How can I&lt;BR /&gt;
&amp;gt;sort the contents of the variable so it would display as&lt;BR /&gt;
&amp;gt;1,2,3,4,5,6,9,10.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;TIA,&lt;BR /&gt;
&amp;gt;Cliff&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&lt;BR /&gt;
--&lt;BR /&gt;
Vlad   http://www.netvision.net.il/php/vnestr/&lt;/CST&gt;</description>
      <pubDate>Tue, 21 Sep 1999 23:30:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888695#M164286</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>1999-09-21T23:30:05Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888696#M164287</link>
      <description>(Doesn't sort string representations of negative integers correctly).&lt;BR /&gt;
&lt;BR /&gt;
________________________________&lt;BR /&gt;
&lt;BR /&gt;
puckettm@cadvision.com&lt;BR /&gt;
&amp;gt;Not&amp;lt; a Member of the AutoDESK&lt;BR /&gt;
Discussion Forum Moderator Program&lt;BR /&gt;
Imagination makes all things possible.&lt;BR /&gt;
________________________________</description>
      <pubDate>Wed, 22 Sep 1999 03:40:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888696#M164287</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>1999-09-22T03:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888697#M164288</link>
      <description>I reviewed all of your responses and comments. And while I originally&lt;BR /&gt;
thought I would somehow use the acad_strlsort function, that function did&lt;BR /&gt;
not seem to completely sort in the manner I desired. The end result would be&lt;BR /&gt;
to have my code display on the command line as follows:  1,2,3,4,9,15&lt;BR /&gt;
instead of the way that tblnext brings it up (by creation number?):&lt;BR /&gt;
1,2,15,9,4 which could represent how the designer was creating sheet layers,&lt;BR /&gt;
as bogus as it seems. At any rate, here is the code I came up with - note&lt;BR /&gt;
thats its only a portion of the full program.&lt;BR /&gt;
&lt;BR /&gt;
(tblnext "layer" T)&lt;BR /&gt;
        (while (setq p2 (tblnext "layer"))          ;find highest sheet&lt;BR /&gt;
number&lt;BR /&gt;
          (setq p2 (cdr (assoc 2 p2 )))&lt;BR /&gt;
          (setq p1 (substr p2 1 1 ))&lt;BR /&gt;
          (if (= p1 "S")&lt;BR /&gt;
            (progn&lt;BR /&gt;
              (if (= e nil)&lt;BR /&gt;
                (setq e 0)&lt;BR /&gt;
               )&lt;BR /&gt;
              (setq d (atoi (substr p2 2)))&lt;BR /&gt;
              (setq e (max d e))&lt;BR /&gt;
             )&lt;BR /&gt;
           )&lt;BR /&gt;
         )&lt;BR /&gt;
        (setq f 0)                                  ;construct the sheet&lt;BR /&gt;
list&lt;BR /&gt;
        (while (&amp;lt;= f e)&lt;BR /&gt;
          (setq f (+ 1 f))&lt;BR /&gt;
          (setq g (strcat "S" (itoa f)))&lt;BR /&gt;
          (if (tblsearch "layer" g)&lt;BR /&gt;
            (cond&lt;BR /&gt;
              ((= p3 nil)(setq p3 (substr g 2)))&lt;BR /&gt;
              ((&amp;gt; e 1)(setq p3 (strcat p3 "," (substr g 2))))&lt;BR /&gt;
             )&lt;BR /&gt;
           )&lt;BR /&gt;
         )&lt;BR /&gt;
          (setq w 1)&lt;BR /&gt;
          (while w                                  ;user input&lt;BR /&gt;
            (princ "\nAvailable sheets: ")&lt;BR /&gt;
            (princ p3)&lt;BR /&gt;
            (setq a (getint "\nEnter sheet number: "))&lt;BR /&gt;
              (if (not (tblsearch "layer" (strcat "S" (itoa a))))&lt;BR /&gt;
                (alert "\nInvalid sheet number")&lt;BR /&gt;
&lt;BR /&gt;
I have the feeling that I could probably do the same thing with fewer lines,&lt;BR /&gt;
but this is what I came up with that seems to work, but I have not&lt;BR /&gt;
completely tested it yet.&lt;BR /&gt;
&lt;BR /&gt;
Thanks everyone for the ideas,&lt;BR /&gt;
Cliff</description>
      <pubDate>Wed, 22 Sep 1999 18:26:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-sort-a-string/m-p/888697#M164288</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>1999-09-22T18:26:46Z</dc:date>
    </item>
  </channel>
</rss>

