<?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: AutoCAD LT Count Table Sorting in AutoCAD LT Forum</title>
    <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082333#M78941</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17323525"&gt;@d_salesU4WW6&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What version of LT are you using?&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI: Only LT 2024 and up can load most lisp functions to run.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Apr 2026 16:10:15 GMT</pubDate>
    <dc:creator>paullimapa</dc:creator>
    <dc:date>2026-04-08T16:10:15Z</dc:date>
    <item>
      <title>AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082143#M78933</link>
      <description>&lt;P&gt;Good Afternoon,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We use count tables for our Legends but currently it sorts by alphabetical order - is there a way to manage the order of the rows in the table? I don't mind whether its a drag and drop I do each time or whether its set into the background of the table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2026 14:01:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082143#M78933</guid>
      <dc:creator>d_salesU4WW6</dc:creator>
      <dc:date>2026-04-08T14:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082213#M78934</link>
      <description>&lt;P&gt;I've not downloaded it, but you can try the app in the link below&lt;/P&gt;
&lt;P&gt;&lt;A href="https://apps.autodesk.com/ACD/en/Detail/Index?id=4790977574413485803" target="_blank"&gt;Table Sort | AutoCAD | Autodesk App Store&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2026 14:45:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082213#M78934</guid>
      <dc:creator>h_s_walker</dc:creator>
      <dc:date>2026-04-08T14:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082233#M78935</link>
      <description>&lt;P&gt;FYI: since&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17323525"&gt;@d_salesU4WW6&lt;/a&gt;&amp;nbsp;is running LT, the app which uses arx to load will most likely not load on LT.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2026 15:05:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082233#M78935</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2026-04-08T15:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082236#M78936</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1137264"&gt;@paullimapa&lt;/a&gt;&amp;nbsp;Yeah you're right. I just tried.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2026 15:11:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082236#M78936</guid>
      <dc:creator>h_s_walker</dc:creator>
      <dc:date>2026-04-08T15:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082269#M78938</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17323525"&gt;@d_salesU4WW6&lt;/a&gt;&amp;nbsp;I've just been working with ChatGPT and have the following lisp for it. It will ask for a column to sort by (0 is the first column). It will recognise if it's letters or numbers and will then ask if you want to sort A-Z or Z-A or 1-9 or 9-1. See the image at the end for the results.&lt;/P&gt;
&lt;P&gt;The only problem that ChatGPT pointed out is LT cannot write fields in a lisp, so it converts all the fields to text.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;(defun isNumber (s)
  (not (null (distof s 2)))
)

(defun c:SortTableByCol ( / ent obj rows cols data colIndex r c rowData sorted numeric order )

  (vl-load-com)

  ;; Select table
  (setq ent (car (entsel "\nSelect table: ")))
  (setq obj (vlax-ename-&amp;gt;vla-object ent))

  (setq rows (vla-get-Rows obj))
  (setq cols (vla-get-Columns obj))

  ;; --- SAFE COLUMN INPUT ---
  (setq colIndex nil)
  (while (not (and colIndex (&amp;gt;= colIndex 0) (&amp;lt; colIndex cols)))
    (setq colIndex
      (getint
        (strcat "\nEnter column index (0-" (itoa (1- cols)) "): ")
      )
    )
    (if (null colIndex)
      (prompt "\nInvalid input. Please enter a number.")
    )
  )

  ;; Extract data (skip header row)
  (setq data '()
        r 1)

  (while (&amp;lt; r rows)
    (setq rowData '()
          c 0)
    (while (&amp;lt; c cols)
      (setq rowData (append rowData (list (vla-GetText obj r c))))
      (setq c (1+ c))
    )
    (setq data (append data (list rowData)))
    (setq r (1+ r))
  )

  ;; Detect numeric column
  (setq numeric (isNumber (nth colIndex (car data))))

  ;; Ask sort order
  (if numeric
    (progn
      (initget "1-9 9-1")
      (setq order (getkword "\nSort order [1-9/9-1] &amp;lt;1-9&amp;gt;: "))
      (if (null order) (setq order "1-9"))
    )
    (progn
      (initget "A-Z Z-A")
      (setq order (getkword "\nSort order [A-Z/Z-A] &amp;lt;A-Z&amp;gt;: "))
      (if (null order) (setq order "A-Z"))
    )
  )

  ;; Sort
  (setq sorted
    (vl-sort data
      (function
        (lambda (a b)
          (if numeric
            (if (= order "1-9")
              (&amp;lt; (atof (nth colIndex a)) (atof (nth colIndex b)))
              (&amp;gt; (atof (nth colIndex a)) (atof (nth colIndex b)))
            )
            (if (= order "A-Z")
              (&amp;lt; (strcase (nth colIndex a)) (strcase (nth colIndex b)))
              (&amp;gt; (strcase (nth colIndex a)) (strcase (nth colIndex b)))
            )
          )
        )
      )
    )
  )

  ;; Write back
  (setq r 1)
  (foreach row sorted
    (setq c 0)
    (foreach val row
      (vla-SetText obj r c val)
      (setq c (1+ c))
    )
    (setq r (1+ r))
  )

  (princ "\nTable sorted.")
  (princ)
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1631713iD4C9D62A76969A9B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2026 15:52:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082269#M78938</guid>
      <dc:creator>h_s_walker</dc:creator>
      <dc:date>2026-04-08T15:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082303#M78939</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17323525"&gt;@d_salesU4WW6&lt;/a&gt;&amp;nbsp;You can also try this one. You need to select the table, and it will list the column number with its' header, then you choose which column and it will sort a-z/1-9, if you run the lisp again and then choose the same column it will reverse the sort order.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;(setq *last-sort-col* nil)
(setq *last-sort-dir* nil)

(defun isNumber (s)
  (not (null (distof s 2)))
)

(defun c:SortTableLT ( / sel ent obj rows cols data headers r c rowData sorted numeric colIndex order valA valB headerStr)

  (vl-load-com)

  ;; --- Select table safely ---
  (setq sel nil)
  (while (not sel)
    (prompt "\nSelect table to sort: ")
    (setq sel (entsel))
    (if (null sel)
      (prompt "\nNo object selected. Try again.")
    )
  )
  (setq ent (car sel))
  (setq obj (vlax-ename-&amp;gt;vla-object ent))

  ;; --- Table info ---
  (setq rows (vla-get-Rows obj))
  (setq cols (vla-get-Columns obj))

  ;; --- Extract header texts ---
  (setq headers '())
  (setq c 0)
  (while (&amp;lt; c cols)
    (setq headers (append headers (list (vla-GetText obj 0 c))))
    (setq c (1+ c))
  )

  ;; --- Show headers with indices ---
  (prompt "\nTable columns:")
  (setq c 0)
  (foreach h headers
    (prompt (strcat "\n" (itoa c) ": " h))
    (setq c (1+ c))
  )

  ;; --- Ask for column index ---
  (setq colIndex nil)
  (while (not (and colIndex (&amp;gt;= colIndex 0) (&amp;lt; colIndex cols)))
    (setq colIndex
          (getint (strcat "\nEnter column index to sort (0-" (itoa (1- cols)) "): ")))
    (if (null colIndex)
      (prompt "\nInvalid input. Please enter a number.")
    )
  )

  ;; --- Extract table data (skip header row 0) ---
  (setq data '())
  (setq r 1)
  (while (&amp;lt; r rows)
    (setq rowData '()
          c 0)
    (while (&amp;lt; c cols)
      (setq rowData (append rowData (list (vla-GetText obj r c))))
      (setq c (1+ c))
    )
    (setq data (append data (list rowData)))
    (setq r (1+ r))
  )

  ;; --- Detect numeric column ---
  (setq numeric (isNumber (nth colIndex (car data))))

  ;; --- Determine sort order (toggle if same column) ---
  (if (and (= *last-sort-col* colIndex) *last-sort-dir*)
    (setq order (if (= *last-sort-dir* "asc") "desc" "asc"))
    (setq order "asc")
  )

  ;; --- Sort data ---
  (setq sorted
        (vl-sort data
                 (function
                  (lambda (a b)
                    (setq valA (nth colIndex a))
                    (setq valB (nth colIndex b))
                    (if numeric
                      (if (= order "asc") (&amp;lt; (atof valA) (atof valB)) (&amp;gt; (atof valA) (atof valB)))
                      (if (= order "asc") (&amp;lt; (strcase valA) (strcase valB)) (&amp;gt; (strcase valA) (strcase valB)))
                    )
                  )
                 )
        )
  )

  ;; --- Write sorted data back ---
  (setq r 1)
  (foreach row sorted
    (setq c 0)
    (foreach val row
      (vla-SetText obj r c val)
      (setq c (1+ c))
    )
    (setq r (1+ r))
  )

  ;; --- Save last sorted column/direction ---
  (setq *last-sort-col* colIndex)
  (setq *last-sort-dir* order)

  (princ (strcat "\nTable sorted by column " (itoa colIndex) " (" (nth colIndex headers) ") in " order " order."))
  (princ)
)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 08 Apr 2026 15:51:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082303#M78939</guid>
      <dc:creator>h_s_walker</dc:creator>
      <dc:date>2026-04-08T15:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082313#M78940</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17323525"&gt;@d_salesU4WW6&lt;/a&gt;&amp;nbsp;The code below remembers the last table you selected&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;;; Global variables to store last table and last sort info
(setq *last-table* nil)
(setq *last-sort-col* nil)
(setq *last-sort-dir* nil)

(defun isNumber (s)
  (not (null (distof s 2)))
)

(defun c:SortTableRepeatLT ( / sel ent obj rows cols data headers r c rowData sorted numeric colIndex order valA valB)

  (vl-load-com)

  ;; --- Select table or use last table ---
  (if (and *last-table* (vlax-ename-&amp;gt;vla-object *last-table*))
    (setq obj (vlax-ename-&amp;gt;vla-object *last-table*))
    ;; Else select new table
    (progn
      (setq sel nil)
      (while (not sel)
        (prompt "\nSelect table to sort: ")
        (setq sel (entsel))
        (if (null sel)
          (prompt "\nNo object selected. Try again.")
        )
      )
      (setq ent (car sel))
      (setq obj (vlax-ename-&amp;gt;vla-object ent))
      (setq *last-table* ent)
    )
  )

  ;; --- Table info ---
  (setq rows (vla-get-Rows obj))
  (setq cols (vla-get-Columns obj))

  ;; --- Extract header texts ---
  (setq headers '())
  (setq c 0)
  (while (&amp;lt; c cols)
    (setq headers (append headers (list (vla-GetText obj 0 c))))
    (setq c (1+ c))
  )

  ;; --- Ask for column index only if first run or new table ---
  (if (or (null *last-sort-col*) (not (eq *last-table* ent)))
    (progn
      (prompt "\nTable columns:")
      (setq c 0)
      (foreach h headers
        (prompt (strcat "\n" (itoa c) ": " h))
        (setq c (1+ c))
      )

      ;; Prompt user for column index
      (setq colIndex nil)
      (while (not (and colIndex (&amp;gt;= colIndex 0) (&amp;lt; colIndex cols)))
        (setq colIndex
              (getint (strcat "\nEnter column index to sort (0-" (itoa (1- cols)) "): ")))
        (if (null colIndex)
          (prompt "\nInvalid input. Please enter a number.")
        )
      )
    )
    ;; Use last column
    (setq colIndex *last-sort-col*)
  )

  ;; --- Extract table data (skip header row 0) ---
  (setq data '())
  (setq r 1)
  (while (&amp;lt; r rows)
    (setq rowData '()
          c 0)
    (while (&amp;lt; c cols)
      (setq rowData (append rowData (list (vla-GetText obj r c))))
      (setq c (1+ c))
    )
    (setq data (append data (list rowData)))
    (setq r (1+ r))
  )

  ;; --- Detect numeric column ---
  (setq numeric (isNumber (nth colIndex (car data))))

  ;; --- Determine sort order (toggle if same column) ---
  (if (and (= *last-sort-col* colIndex) *last-sort-dir*)
    (setq order (if (= *last-sort-dir* "asc") "desc" "asc"))
    (setq order "asc")
  )

  ;; --- Sort data ---
  (setq sorted
        (vl-sort data
                 (function
                  (lambda (a b)
                    (setq valA (nth colIndex a))
                    (setq valB (nth colIndex b))
                    (if numeric
                      (if (= order "asc") (&amp;lt; (atof valA) (atof valB)) (&amp;gt; (atof valA) (atof valB)))
                      (if (= order "asc") (&amp;lt; (strcase valA) (strcase valB)) (&amp;gt; (strcase valA) (strcase valB)))
                    )
                  )
                 )
        )
  )

  ;; --- Write sorted data back ---
  (setq r 1)
  (foreach row sorted
    (setq c 0)
    (foreach val row
      (vla-SetText obj r c val)
      (setq c (1+ c))
    )
    (setq r (1+ r))
  )

  ;; --- Save last table, column, and direction ---
  (setq *last-table* (vlax-vla-object-&amp;gt;ename obj))
  (setq *last-sort-col* colIndex)
  (setq *last-sort-dir* order)

  (princ (strcat "\nTable sorted by column " (itoa colIndex) " (" (nth colIndex headers) ") in " order " order."))
  (princ)
)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 08 Apr 2026 15:58:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082313#M78940</guid>
      <dc:creator>h_s_walker</dc:creator>
      <dc:date>2026-04-08T15:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082333#M78941</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17323525"&gt;@d_salesU4WW6&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What version of LT are you using?&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI: Only LT 2024 and up can load most lisp functions to run.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2026 16:10:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082333#M78941</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2026-04-08T16:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082358#M78943</link>
      <description>&lt;P&gt;The lisps all work in LT2026. I tested them myself.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2026 16:24:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14082358#M78943</guid>
      <dc:creator>h_s_walker</dc:creator>
      <dc:date>2026-04-08T16:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083316#M78948</link>
      <description>&lt;P&gt;Hi Paul,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm running 2026&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2026 08:06:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083316#M78948</guid>
      <dc:creator>d_salesU4WW6</dc:creator>
      <dc:date>2026-04-09T08:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083333#M78949</link>
      <description>&lt;P&gt;Unfortunately it needs to be a custom sort as we have CIE panels that would go above detection and interfaces would go near the bottom ect&lt;/P&gt;&lt;P&gt;I have attached below the way the table sorts now and how it would need to be sorted. At the moment its a manual task inserting and removing rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-04-09 090845.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1631938iC21D152FA783621F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2026-04-09 090845.png" alt="Screenshot 2026-04-09 090845.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-04-09 091852.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1631939i700570C69652AE4D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2026-04-09 091852.png" alt="Screenshot 2026-04-09 091852.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2026 08:20:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083333#M78949</guid>
      <dc:creator>d_salesU4WW6</dc:creator>
      <dc:date>2026-04-09T08:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083363#M78950</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17323525"&gt;@d_salesU4WW6&lt;/a&gt;&amp;nbsp;Try this one. It asks Auto or Manual. If manual it will ask for the row order and then sort on that. EDIT: I just got ChatGPT to sort the table if it has blocks in it as well. The only problem is if the block has an attribute in it, it will lose the attribute value&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 912px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1631949i149F8CC67887DD75/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;(defun isNumber (s)
  (not (null (distof s 2)))
)

(defun parseOrder (str / lst pos)
  (setq lst '())
  (while (setq pos (vl-string-search "," str))
    (setq lst (cons (atoi (substr str 1 pos)) lst))
    (setq str (substr str (+ pos 2)))
  )
  (setq lst (cons (atoi str) lst))
  (reverse lst)
)

;; =========================
;; 🔹 CELL HANDLING (BLOCKS ONLY)
;; =========================

(defun getCellData (obj r c / cellType txt blk)
  (setq cellType (vla-GetCellType obj r c))
  (setq txt (vla-GetText obj r c))
  (setq blk nil)

  ;; 2 = block cell
  (if (= cellType 2)
    (setq blk (vla-GetBlockTableRecordId obj r c))
  )

  (list cellType txt blk)
)

(defun setCellData (obj r c data / cellType txt blk)
  (setq cellType (nth 0 data))
  (setq txt      (nth 1 data))
  (setq blk      (nth 2 data))

  (cond
    ;; Block cell
    ((= cellType 2)
      (vla-SetBlockTableRecordId obj r c blk :vlax-true)
    )
    ;; Text cell
    (T
      (vla-SetText obj r c txt)
    )
  )
)

;; =========================
;; 🔹 MAIN FUNCTION
;; =========================

(defun c:SortTableAdvanced ( / ent obj rows cols data colIndex r c rowData sorted numeric order mode input )

  (vl-load-com)

  ;; Select table
  (setq ent (car (entsel "\nSelect table: ")))
  (if (null ent) (exit))
  (setq obj (vlax-ename-&amp;gt;vla-object ent))

  (setq rows (vla-get-Rows obj))
  (setq cols (vla-get-Columns obj))

  ;; Extract data (skip header row)
  (setq data '()
        r 1)

  (while (&amp;lt; r rows)
    (setq rowData '()
          c 0)
    (while (&amp;lt; c cols)
      (setq rowData (append rowData (list (getCellData obj r c))))
      (setq c (1+ c))
    )
    (setq data (append data (list rowData)))
    (setq r (1+ r))
  )

  ;; Ask mode
  (initget "Auto Manual")
  (setq mode (getkword "\nChoose mode [Auto/Manual] &amp;lt;Auto&amp;gt;: "))
  (if (null mode) (setq mode "Auto"))

  ;; =========================
  ;; 🔹 MANUAL MODE
  ;; =========================
  (if (= mode "Manual")
    (progn
      (prompt (strcat "\nNumber of data rows: " (itoa (length data))))
      (setq input (getstring "\nEnter new row order (e.g. 3,1,2,4): "))
      (setq order (parseOrder input))

      (setq r 1)
      (foreach idx order
        (if (and (&amp;gt;= idx 1) (&amp;lt;= idx (length data)))
          (progn
            (setq rowData (nth (1- idx) data))
            (setq c 0)
            (foreach cell rowData
              (setCellData obj r c cell)
              (setq c (1+ c))
            )
            (setq r (1+ r))
          )
        )
      )

      (prompt "\nTable reordered manually.")
    )

    ;; =========================
    ;; 🔹 AUTO MODE
    ;; =========================
    (progn

      ;; Column input
      (setq colIndex nil)
      (while (not (and colIndex (&amp;gt;= colIndex 0) (&amp;lt; colIndex cols)))
        (setq colIndex
          (getint
            (strcat "\nEnter column index (0-" (itoa (1- cols)) "): ")
          )
        )
        (if (null colIndex)
          (prompt "\nInvalid input. Please enter a number.")
        )
      )

      ;; Detect numeric
      (setq numeric (isNumber (nth 1 (nth colIndex (car data)))))

      ;; Sort order prompt
      (if numeric
        (progn
          (initget "1-9 9-1")
          (setq order (getkword "\nSort order [1-9/9-1] &amp;lt;1-9&amp;gt;: "))
          (if (null order) (setq order "1-9"))
        )
        (progn
          (initget "A-Z Z-A")
          (setq order (getkword "\nSort order [A-Z/Z-A] &amp;lt;A-Z&amp;gt;: "))
          (if (null order) (setq order "A-Z"))
        )
      )

      ;; Sort
      (setq sorted
        (vl-sort data
          (function
            (lambda (a b)
              (if numeric
                (if (= order "1-9")
                  (&amp;lt; (atof (nth 1 (nth colIndex a)))
                     (atof (nth 1 (nth colIndex b))))
                  (&amp;gt; (atof (nth 1 (nth colIndex a)))
                     (atof (nth 1 (nth colIndex b))))
                )
                (if (= order "A-Z")
                  (&amp;lt; (strcase (nth 1 (nth colIndex a)))
                     (strcase (nth 1 (nth colIndex b))))
                  (&amp;gt; (strcase (nth 1 (nth colIndex a)))
                     (strcase (nth 1 (nth colIndex b))))
                )
              )
            )
          )
        )
      )

      ;; Write back
      (setq r 1)
      (foreach row sorted
        (setq c 0)
        (foreach cell row
          (setCellData obj r c cell)
          (setq c (1+ c))
        )
        (setq r (1+ r))
      )

      (prompt "\nTable sorted automatically.")
    )
  )

  (princ)
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2026 09:15:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083363#M78950</guid>
      <dc:creator>h_s_walker</dc:creator>
      <dc:date>2026-04-09T09:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083406#M78953</link>
      <description>&lt;P&gt;You are amazing! Thank you so much! If I'm using a COUNT table will this still update when blocks added?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2026 09:11:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083406#M78953</guid>
      <dc:creator>d_salesU4WW6</dc:creator>
      <dc:date>2026-04-09T09:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083416#M78954</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17323525"&gt;@d_salesU4WW6&lt;/a&gt;&amp;nbsp;Yes. If you look at the image I posted that was a count table I created, and I added the blocks to it. Just remember that the fields will not be remembered so you will have to keep a spare table somewhere just in case you delete / add blocks, and then you don't have to count them again, just copy the table and run the lisp on the copy.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2026 09:23:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083416#M78954</guid>
      <dc:creator>h_s_walker</dc:creator>
      <dc:date>2026-04-09T09:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083429#M78956</link>
      <description>&lt;P&gt;Thanks so much - You've been a massive help! Legends have been a massive pain point for us.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2026 09:33:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083429#M78956</guid>
      <dc:creator>d_salesU4WW6</dc:creator>
      <dc:date>2026-04-09T09:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD LT Count Table Sorting</title>
      <link>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083434#M78957</link>
      <description>&lt;P&gt;You're welcome&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2026 09:35:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/autocad-lt-forum/autocad-lt-count-table-sorting/m-p/14083434#M78957</guid>
      <dc:creator>h_s_walker</dc:creator>
      <dc:date>2026-04-09T09:35:39Z</dc:date>
    </item>
  </channel>
</rss>

