<?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: Sort help in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6833159#M130666</link>
    <description>&lt;P&gt;I did not dig into it very much, just blind shot... looks like it is working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun cableRenum_sortList (xL)

(vl-sort xL
	'(lambda (a b)
		(or	
			(&amp;lt; 
				(atof (rtos (cadr (assoc 11 (entget (car a)))) 2 5))
				(atof (rtos (cadr (assoc 11 (entget (car b)))) 2 5))
			) ;&amp;lt; X X'

...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Jan 2017 14:58:17 GMT</pubDate>
    <dc:creator>ВeekeeCZ</dc:creator>
    <dc:date>2017-01-26T14:58:17Z</dc:date>
    <item>
      <title>Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429234#M130652</link>
      <description>&lt;P&gt;Good day!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to be able to sort a list of points ascending&amp;nbsp;by there X coordinate and if the X coordinates are the same, sort those points descending by there Y coordinates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I looked around and found the&amp;nbsp;X coordinate sorting&amp;nbsp;and tailored it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(setq eList (vl-sort (append i3List i4List)
	(function (lambda (x y) (&amp;lt; 
		(cadr (assoc 10 (entget (&lt;FONT color="#ff0000"&gt;car x&lt;/FONT&gt;)))) 
		(cadr (assoc 10 (entget (&lt;FONT color="#ff0000"&gt;car y&lt;/FONT&gt;))))	))))) ;sorts by X coordinate&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The red code...&amp;nbsp;"(car x)" and "(car y)" are enames.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure of how to implement an IF statement when the X coordinates match, inside the vl-sort function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help, please.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 14:58:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429234#M130652</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2016-07-11T14:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429313#M130653</link>
      <description>&lt;P&gt;Here is a quick test function. Sort it by y-coord first, then x-coord.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;(defun c:test ( / ss lst i )

  (setq ss (ssget))
  
  (repeat (setq i (sslength ss))
    (setq lst (cons (ssname ss (setq i (1- i))) lst)))

  (setq lst (vl-sort lst (function (lambda (x y) (&amp;lt; (caddr (assoc 10 (entget x)))
						    (caddr (assoc 10 (entget y)))))))
	lst (vl-sort lst (function (lambda (x y) (&amp;lt; (cadr (assoc 10 (entget x)))
						    (cadr (assoc 10 (entget y))))))))

  (command "pline")
  (foreach e lst (command "_none" (cdr (assoc 10 (entget e)))))
  (command)	   
    
  (princ)
)&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 15:34:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429313#M130653</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2016-07-11T15:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429361#M130654</link>
      <description>&lt;P&gt;Thanks for the quick reply, BCZ.&lt;BR /&gt;&lt;BR /&gt;However, this isn't quite what I need. I only want to sort&amp;nbsp;points by their Y components&amp;nbsp;IF their&amp;nbsp;X components are identical.&lt;BR /&gt;&lt;BR /&gt;Basically, I need a tie-breaker between points that are aligned and I'd prefer to sort THESE points only by their Y location.&lt;BR /&gt;&lt;BR /&gt;Does this make sense?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 15:46:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429361#M130654</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2016-07-11T15:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429393#M130655</link>
      <description>&lt;P&gt;I've attached a visual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the order of the points in the list to mimic how the points are numbered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P1 is first, followed by P2, P3, P4,&amp;nbsp;and P5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You'll notice how P2, P3, and P4 are aligned vertically and I want point on top (P2) to be listed before the points below it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, left to right and (if needed)&amp;nbsp;top to bottom.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 15:54:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429393#M130655</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2016-07-11T15:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429609#M130656</link>
      <description>&lt;P&gt;According to your posted picture...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(defun c:sort-texts ( / ss l k )&lt;BR /&gt;&amp;nbsp; (prompt "\nSelect text entities labeled with only single letter \"p\" which are positioned according to sorting rules...")&lt;BR /&gt;&amp;nbsp; (setq ss (ssget "_:L" '((0 . "TEXT"))))&lt;BR /&gt;&amp;nbsp; (setq l (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))&lt;BR /&gt;&amp;nbsp; (setq l (vl-sort l '(lambda ( a b ) (if (equal (car (cdr (assoc 10 (entget a)))) (car (cdr (assoc 10 (entget b)))) 1e-6)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&amp;gt; (cadr (cdr (assoc 10 (entget a)))) (cadr (cdr (assoc 10 (entget b)))))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&amp;lt; (car (cdr (assoc 10 (entget a)))) (car (cdr (assoc 10 (entget b)))))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; (setq k 0)&lt;BR /&gt;&amp;nbsp; (foreach e l&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (entupd (cdr (assoc -1 (entmod (subst (cons 1 (strcat (cdr (assoc 1 (entget e))) (itoa (setq k (1+ k))))) (assoc 1 (entget e)) (entget e))))))&lt;BR /&gt;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; (princ)&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 17:20:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429609#M130656</guid>
      <dc:creator>marko_ribar</dc:creator>
      <dc:date>2016-07-11T17:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429739#M130657</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/525418"&gt;@zph&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;....&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to be able to sort a list of points ascending&amp;nbsp;by there X coordinate and if the X coordinates are the same, sort those points descending by there Y coordinates.&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could modify code from BlockSSSort.lsp, available &lt;A href="https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/assigning-attributes-to-blocks-using-polyline-to-sequence-order/m-p/3147910#M298974" target="_self"&gt;here&lt;/A&gt;.&amp;nbsp; It stands for &lt;STRONG&gt;Block&lt;/STRONG&gt; &lt;STRONG&gt;S&lt;/STRONG&gt;election &lt;STRONG&gt;S&lt;/STRONG&gt;et &lt;STRONG&gt;Sort&lt;/STRONG&gt;, and it's made to sort a&amp;nbsp;selection set&amp;nbsp;of &lt;EM&gt;Blocks&lt;/EM&gt; into a list ordered by insertion-point positions in both directions, but you can alter it to take a list of &lt;EM&gt;points&lt;/EM&gt; as input.&amp;nbsp; It sorts by one coordinate comparison, and wherever that coordinate is the same for more than one of them, it keeps those in a separate sublist, which it then sorts by comparison in the other direction.&amp;nbsp; Its arguments specify which edge to start with, and in which direction to sort within each aligned sublist.&amp;nbsp; For the directions you describe, with &lt;EM&gt;Blocks&lt;/EM&gt; the usage would be (BSSS "&lt;STRONG&gt;L&lt;/STRONG&gt;" "&lt;STRONG&gt;T&lt;/STRONG&gt;"), that is, sort starting on the &lt;STRONG&gt;L&lt;/STRONG&gt;eft side, sorting any multiples that align [in the X direction in that case] from the&amp;nbsp;&lt;STRONG&gt;T&lt;/STRONG&gt;op down.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to tailor it to exactly what your input is -- it takes a &lt;EM&gt;User object(s) selection&lt;/EM&gt;, but it&amp;nbsp;seems from your description that you are starting with a &lt;EM&gt;list of point-coordinate lists&lt;/EM&gt;, which is one alteration to BlockSSSort,&amp;nbsp;and it would be an easy adjustment to use &lt;EM&gt;User on-screen point picks&lt;/EM&gt; instead.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 18:06:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6429739#M130657</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2016-07-11T18:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6430263#M130658</link>
      <description>&amp;gt;&amp;gt; So, left to right and (if needed) top to bottom.&lt;BR /&gt;&lt;BR /&gt;You might need to position your points in the&lt;BR /&gt;Fourth Quadrant for it to work LtoR and TtoB...&lt;BR /&gt;&lt;BR /&gt;???&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Jul 2016 22:21:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6430263#M130658</guid>
      <dc:creator>scot-65</dc:creator>
      <dc:date>2016-07-11T22:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6430883#M130659</link>
      <description>&lt;P&gt;try this:&lt;BR /&gt;dwg attachment with test points:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Code of (test1):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(defun test1 ( / MiList get10)
  (setq	MiList
	 '(("P1" (2081.59 936.449 0.0))
	   ("P3" (2088.04 940.865 0.0))
	   ("P5" (2094.3 939.376 0.0))
	   ("P8" (2101.77 940.865 0.0))
	   ("P4" (2088.04 936.42 0.0))
	   ("P2" (2088.04 943.495 0.0))
	   ("P6" (2094.3 936.477 0.0))
	   ("P9" (2099.8 936.614 0.0))
	   ("P7" (2099.8 944.333 0.0))
	  )
  )
  (setq L1 (vl-sort
	   MiList
	   (function
	     (lambda (e1 e2)
	       (or
		(&amp;lt; (caadr e1) (caadr e2)) ;; &amp;lt; X X'
		(and
		 (equal (caadr e1) (caadr e2)) ;; equal X X'
		 (&amp;gt; (cadadr e1) (cadadr e2))   ;; &amp;gt; Y Y'
		)
	       )
	     )
	    )
	  )
  )
)&lt;/PRE&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;PRE&gt;(("P1" (2081.59 936.449 0.0))
  ("P2" (2088.04 943.495 0.0))
  ("P3" (2088.04 940.865 0.0))
  ("P4" (2088.04 936.42 0.0))
  ("P5" (2094.3 939.376 0.0))
  ("P6" (2094.3 936.477 0.0))
  ("P7" (2099.8 944.333 0.0))
  ("P9" (2099.8 936.614 0.0))
  ("P8" (2101.77 940.865 0.0))
)&lt;/PRE&gt;&lt;P&gt;regards..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 09:20:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6430883#M130659</guid>
      <dc:creator>joselggalan</dc:creator>
      <dc:date>2016-07-12T09:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432102#M130660</link>
      <description>It's all in the details. Thank you Marko, Kent, Scott, and Jose for your replies.&lt;BR /&gt;&lt;BR /&gt;However, until I realized that I needed to be using ASSOC 11 rather than 10, all my attempts had been in vain. Assoc 10, the insertion point on a text entity, changes based upon text length (the actual length...not character length). Assoc 11, the corresponding justification point, stays the same regardless of text length.&lt;BR /&gt;&lt;BR /&gt;Thank you for showing me how to incorporate more complicated comparisons into the vl-sort function.</description>
      <pubDate>Tue, 12 Jul 2016 18:28:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432102#M130660</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2016-07-12T18:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432180#M130661</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/525418"&gt;@zph&lt;/a&gt; wrote:&lt;BR /&gt;...&lt;BR /&gt;However, until I realized that I needed to be using ASSOC 11 rather than 10, all my attempts had been in vain. Assoc 10, the insertion point on a text entity, changes based upon text length (the actual length...not character length). Assoc 11, the corresponding justification point, stays the same regardless of text length.&lt;BR /&gt;...&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;zph, FYI if you have a default text alignment, then (cdr (assoc 11 (entget (car (entsel))))) returns '(0 0 0)! Try any text in Marco's test file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simple condition could be that if 11 code equals to '(0 0 0), then take code 10. But there is a small probability that 11 is actually '(0 0 0) on purpose.&lt;/P&gt;
&lt;P&gt;More reliable is that if both codes 72 and 73 are 0, then take code 10.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 18:54:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432180#M130661</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2016-07-12T18:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432204#M130662</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/525418"&gt;@zph&lt;/a&gt; wrote:&lt;BR /&gt;.... Assoc 10, the insertion point on a text entity, changes based upon text length (the actual length...not character length). Assoc 11, the corresponding justification point, stays the same regardless of text length.&lt;BR /&gt;....&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's actually a little more convoluted than that. &amp;nbsp;Assoc 10 is always the left end of the baseline of the Text object. &amp;nbsp;If it's ordinary Left-justified, that is also the insertion point [to which Osnap INS will snap], and Assoc 11 is always 0,0,0, regardless of position in the drawing, so using the 11 value can lead you astray. &amp;nbsp;If the justification is anything &lt;EM&gt;other than&lt;/EM&gt; Left, Assoc 10 is still the left end of the baseline, and Assoc 11 is the insertion point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to be sure you get what you want, no matter what the Text's justification, you might want to extract insertion points with a test -- if &lt;EM&gt;both&lt;/EM&gt; Assoc 72 and Assoc 73 values are 0, it's Left-justified, and its insertion point is Assoc 10, but if either of those is &lt;EM&gt;not&lt;/EM&gt; zero [except see the next paragraph], it's some other justification and its insertion point is Assoc 11.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BUT it's even more complicated if you ever use Fit or Aligned justifications. &amp;nbsp;10 is the left end of the baseline, 11 the right end, and you would need to choose one, or maybe use the point halfway in between. &amp;nbsp;For Fit, the Assoc 72 value is 5 and 73 is 0; for Aligned, 72 is 3 and 73 is 0. &amp;nbsp;You could also check justification via VLA properties instead of with a check on &lt;EM&gt;two&lt;/EM&gt; different Assoc values.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 18:58:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432204#M130662</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2016-07-12T18:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432221#M130663</link>
      <description>Well, thank you for clearing that up, Kent.&lt;BR /&gt;&lt;BR /&gt;I am impressed. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers!</description>
      <pubDate>Tue, 12 Jul 2016 19:03:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432221#M130663</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2016-07-12T19:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432306#M130664</link>
      <description>Thank you for the recommendation, BCZ.&lt;BR /&gt;&lt;BR /&gt;I'll put this on the LISP list of things to do...the next order is work my spanking new 'ordered-by-location' list into the an already established routine.&lt;BR /&gt;&lt;BR /&gt;Should be fun &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 12 Jul 2016 19:37:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6432306#M130664</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2016-07-12T19:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6833108#M130665</link>
      <description>&lt;P&gt;Wow, it has been a while.&amp;nbsp; It seems I've run into an error with the overall routine incorporating this sorting function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, take a look at the attached .dwg file too see the problem, the noted&amp;nbsp;issue, and the desired result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am fairly certain that the error lies somewhere&amp;nbsp;in the sorting function which is why I am posting back here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is worth noting that this error does NOT occur all the time.&amp;nbsp; For some reason, it is occurring with this selection set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The routine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(defun c:cable_renum ( / adoc eFlag aList bList fD *error* ssBubs i8List cList cList2
			wP1 wP2 iList cTvLc tList eList i3List i4List i5List i6List i7List tVal iClist tCt tNum)

(vl-load-com)
(vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setvar "cmdecho" 0)
(setq eFlag 1 ssBubs (ssadd)
	aList (list 	"A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" 
			"N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z")
	bList (list 	"LMR" ))

;***************;
(setq fD 1.25)	; fuzz distance for text alignment in cableRenum_sortList
;***************;

(defun *error* (msg)
	(if (member msg '("quit / exit abort" "Conversion failed." "*Cancel*"))
		(progn (setvar "cmdecho" 1)(vla-endundomark adoc)
			(cond
				((= eFlag 1) (princ "\n &amp;lt;!&amp;gt; Routine aborted &amp;lt;!&amp;gt; "))
				((= eFlag 2) (princ "\n &amp;lt;!&amp;gt; Cable values adjusted &amp;lt;!&amp;gt; "))
			) ;cond
		) ;progn
	) ;if
) ;*error*

(cableRenum_getReady)
(cableRenum_getAllCables wP1 wP2)
(cableRenum_idBUBREFs wP1 wP2)
(cableRenum_consolidate)
(cableRenum_parse)

(if (&amp;gt; (sslength ssBubs) 0) (command "chprop" ssBubs "" "c" "1" ""))
(setq eFlag 2)
(exit)
) ;cable_renum


;;;;;-----=====     subFunction:  cableRenum_getReady     =====-----;;;;;


(defun cableRenum_getReady ()

(if 	(not 	(and 	(princ "\n\033\n Select two points for crossing window ")
			(setq wP1 (getpoint "\n &amp;lt;.&amp;gt; Select 1st point "))
			(setq wP2 (getpoint "\n &amp;lt;.&amp;gt; Select 2nd point "))
		) ;and
	) ;not

	(progn (princ "\n Two points required ")(exit))
	(progn (command "zoom" "w" wP1 wP2)(alert " Please, wait while routine completes\n\n\n...click OK to continue "))
) ;if

) ;cableRenum_getReady


;;;;;-----=====     subFunction:  cableRenum_getAllCables     =====-----;;;;;


(defun cableRenum_getAllCables (wP1 wP2 / allC tCntr aFlag tName tVal tLen tempL)

(if (setq allC (ssget "_C" wP1 wP2 '((0 . "TEXT")(8 . "TEXT")(67 . 0))) tCntr 0)
	(while (&amp;lt; tCntr (sslength allC))
	(setq aFlag "T" tName (ssname allC tCntr) tVal (cdr (assoc 1 (entget tName))) tLen (strlen tVal))	

		(if (&amp;gt;= tLen 3)
			(progn
			(setq tempL (mapcar 'chr (vl-string-&amp;gt;list (substr tVal (- tLen 2)))))
			(foreach l tempL (if (member l aList) (setq aFlag "F")))
			(if (member (substr tVal 1 3) bList) (setq aFlag "F"))
			) ;progn
		) ;if

		(if	(and	(= aFlag "T")
				(&amp;gt; tLen 10)
				(wcmatch (substr tVal (- tLen 3) 1) "-")
				(wcmatch (substr tVal (- tLen 7) 1) "-")
				(= (vl-string-search "," tVal) nil)
				(= (vl-string-search " " tVal) nil)
			) ;and	

		(setq iList (append iList (list tName)))
		) ;if

	(setq tCntr (1+ tCntr))
	) ;while

	(progn (princ "\n\033\n &amp;lt; Selection set empty &amp;gt; ")(exit))
) ;if

) ;cableRenum_getAllCables


;;;;;-----=====     subFunction:  cableRenum_idBUBREFs     =====-----;;;;;


(defun cableRenum_idBUBREFs (wP1 wP2 / ssC ssV cList vList vFlag cntrC cntrV cIpnt pt1 pt2 lpt1 lpt2 
				bFind lFind sPnt ePnt tFind)

(if (setq vFlag 0 cntrC 0 cntrV 0 ssC (ssget "_C" wP1 wP2 '((0 . "CIRCLE")(8 . "TEXT")(40 . 0.25))))
	(progn
	(setq ssV (ssget "X" '((0 . "LWPOLYLINE")(8 . "0,VIEWPORT")(67 . 0))))
	(while (&amp;lt; cntrC (sslength ssC)) (setq cList (cons (ssname ssC cntrC) cList) cntrC (1+ cntrC)))
	(while (&amp;lt; cntrV (sslength ssV)) (setq vList (cons (ssname ssV cntrV) vList) cntrV (1+ cntrV)))
	(if (= (getvar "tilemode") 0) (setvar "tilemode" 1))

		(foreach c cList
			(progn
			(setq vFlag 0 cIpnt (cdr (assoc 10 (entget c))))
			(vla-getboundingbox (vlax-ename-&amp;gt;vla-object c) 'pt1 'pt2)
			(setq 	pt1 (vlax-safearray-&amp;gt;list pt1) pt2 (vlax-safearray-&amp;gt;list pt2)
				lpt1 (list (- (car pt1) 0.025) (- (cadr pt1) 0.025))
				lpt2 (list (+ (car pt2) 0.025) (+ (cadr pt2) 0.025)))	

				(if (setq bFind (ssget "X" (list	
					'(0 . "TEXT")'(8 . "TEXT")'(67 . 0)
					'(-4 . "&amp;lt;AND")
					'(-4 . "&amp;gt;,&amp;gt;,=") (cons 10 (list (car pt1) (cadr pt1)))
					'(-4 . "&amp;lt;,&amp;lt;,=") (cons 10 (list (car pt2) (cadr pt2)))
					'(-4 . "AND&amp;gt;"))))

(foreach v vList
	(if (= vFlag 0)
		(progn
		(vla-getboundingbox (vlax-ename-&amp;gt;vla-object v) 'pt1 'pt2)
		(setq pt1 (vlax-safearray-&amp;gt;list pt1) pt2 (vlax-safearray-&amp;gt;list pt2))

			(if	(and	(&amp;gt;= (car cIpnt) (car pt1))(&amp;gt;= (cadr cIpnt) (cadr pt1))
					(&amp;lt;= (car cIpnt) (car pt2))(&amp;lt;= (cadr cIpnt) (cadr pt2)))
							
(if (setq lFind (ssget "_C" lpt1 lpt2 '((0 . "LINE")(8 . "WIRE")(67 . 0))))

	(if	(setq	sPnt (cdr (assoc 10 (entget (ssname lFind 0))))
			ePnt (cdr (assoc 11 (entget (ssname lFind 0))))
			tFind (ssget "_W" sPnt (list (car ePnt) (+ (cadr ePnt) 0.25)) 
				'((0 . "TEXT")(8 . "TEXT")(67 . 0))))
	
		(setq vFlag 1 cTvLc (cons (list
			c 
			(ssname bFind 0)
			(cdr (assoc 1 (entget (ssname bFind 0))))
			v 	
			(ssname lFind 0) 
			(ssname tFind 0)
			(cdr (assoc 1 (entget (ssname tFind 0))))) cTvLc))
	) ;if
) ;if
			) ;if
		) ;progn
	) ;if
) ;foreach
				) ;if
			) ;progn
		) ;foreach
	) ;progn
) ;if

) ;cableRenum_idBUBREFs


;;;;;-----=====     subFunction:  cableRenum_consolidate     =====-----;;;;;


(defun cableRenum_consolidate ( / zList rFlag cVal)

(foreach c cTvLc (setq zList (cons (list (nth 5 c) (nth 1 c)) zList)))

(foreach iL iList
	(progn
	(setq rFlag "F" cVal (cdr (assoc 1 (entget iL))))
	(foreach z zList (if (equal iL (car z)) (setq rFlag "T")))
	(if (= rFlag "F") (setq i3List (cons (list iL) i3List)))

		(if (= (member (list (substr cVal 1 (- (strlen cVal) 3))) tList) nil)
		(setq tList (cons (list (substr cVal 1 (- (strlen cVal) 3))) tList))
		) ;if
	) ;progn
) ;foreach

(foreach i3 i3List (progn (princ "\n i3List:  ")(princ i3)(princ "   ")(princ (cdr (assoc 1 (entget (car i3)))))))

(foreach z zList 
	(setq 	i4List (cons (list 
				(nth 0 z)
				(cdr (assoc 1 (entget (nth 0 z))))
				(cdr (assoc 1 (entget (nth 1 z))))) i4List)
		i7List (cons (cdr (assoc 1 (entget (nth 1 z)))) i7List)
	) ;setq
) ;foreach

(setq 	i7List (cableRenum_Count i7List)
	eList (append i3List i4List)
 	tList (vl-sort tList '(lambda (x y) (&amp;lt; (car x) (car y)))))

) ;cableRenum_consolidate


;;;;;-----=====     subFunction:  cableRenum_parse     =====-----;;;;;


(defun cableRenum_parse ( / tCt sCntr sCntr3 tRlist tSlist tTlist tUlist tVlist tUlen i7len i8List tUl itQA sCntr2)

(foreach t1 tList			
	(progn
	(setq sCntr 0 tSlist () i5List () tRlist () i8List ())
		(foreach e1 eList
			(if	(and	(not (= eList nil))
					(not (= e1 nil))
					(equal  
						(substr 
							(cdr (assoc 1 (entget (car e1)))) 
							1 
							(- (strlen (cdr (assoc 1 (entget (car e1))))) 3)
						) ;substr
						(car t1)
					) ;equal
				) ;and

				(progn
				(cableRenum_PnI)
				(cableRenum_increase)
				) ;progn
			) ;if
		) ;foreach
	) ;progn
) ;foreach

) ;cableRenum_parse


;;;;;-----=====     subFunction:  cableRenum_PnI     =====-----;;;;;


(defun cableRenum_PnI ( / )

(if (= (member e1 i4List) nil)
	(setq i8List (cons e1 i8List))

	(progn
	(setq 	tTlist () tUlist () tVlist () 
		itQA 0
		sCntr3 0 
		i4List (vl-sort i4List '(lambda (x y) (&amp;lt; (caddr x) (caddr y)))))

		(while (&amp;lt; sCntr (length i4List))
			(foreach i7 i7List		; find QAs of BUBREFs
			(if (= (caddr (nth sCntr i4List)) (car i7)) (setq itQA (cdr i7)))
			) ;foreach

		(setq tRlist () sCntr2 0 titQA (+ itQA sCntr3))

			(while (&amp;lt; sCntr3 titQA)
			(setq 	tRlist (append tRlist (list (nth sCntr3 i4List)))
				sCntr3 (1+ sCntr3))
			) ;while

			(setq 	tSlist (cableRenum_sortList tRlist) 
				sCntr (+ sCntr itQA) 
				sCntr2 0
				tTlist (append tTlist (list tSlist))
			) ;setq

			(foreach tT tTlist
				(progn
				(setq tUlist ())
					(foreach ta tT
						(setq tUlist 
							(append tUlist 
								(list (car ta))
							) ;append
						) ;setq
					) ;foreach
				(setq tVlist (append tVlist (list tUlist)))
				) ;progn
			) ;foreach					
		) ;while

		(setq tSlist tTlist)

	(setq i7len (length i7List) tRlist ())

		(while (&amp;gt; i7len 0)
			(setq 	tRlist (cons (last tVlist) tRlist)
				tVlist (vl-remove (last tVlist) tVlist)
				i7len (1- i7len)
			) ;setq
		) ;while

		(foreach tS tSlist
			(if (or (= (length tS) 1)(&amp;gt; (length tS) 2))
			(foreach ta tS (setq ssBubs (ssadd (car ta) ssBubs)))
			) ;if
		) ;foreach

	(setq i5List tRlist)
	) ;progn
) ;if

) ;cableRenum_PnI


;;;;;-----=====     subFunction:  cableRenum_increase     =====-----;;;;;


(defun cableRenum_increase ( / )

(setq tCt 1 i6List (cableRenum_sortList (append i8List i5List)))

(foreach i6 i6List
	(progn
		(foreach ia i6
			(progn
				(setq	tL (entget ia) 
					tNum (cond ((= (strlen (itoa tCt)) 1) (strcat "00" (itoa tCt)))
						   ((= (strlen (itoa tCt)) 2) (strcat "0" (itoa tCt)))
						   ((= (strlen (itoa tCt)) 3) (itoa tCt)))
					tVal (strcat (car t1) tNum)
					tL (subst (cons 1 tVal) (assoc 1 tL) tL)
				) ;setq
			(entmod tL)
			) ;progn
		) ;foreach

	(setq tCt (1+ tCt))
	) ;progn
) ;foreach

) ;cableRenum_increase


;;;;;-----=====     subFunction:  cableRenum_sortList     =====-----;;;;;


(defun cableRenum_sortList (xL)

(vl-sort xL
	'(lambda (a b)
		(or	
			(&amp;lt; 
				(cadr (assoc 11 (entget (car a))))
				(cadr (assoc 11 (entget (car b))))
			) ;&amp;lt; X X'

			(and	
				(equal 
					(cadr (assoc 11 (entget (car a))))
					(cadr (assoc 11 (entget (car b)))) 
				fD) ;equal X X'

				(&amp;gt; 
					(caddr (assoc 11 (entget (car a)))) 
					(caddr (assoc 11 (entget (car b))))
				) ;&amp;gt; Y Y'
			) ;and
		) ;or
	) ;lambda
) ;vl-sort

) ;cableRenum_sortList


;;;;;-----=====     subFunction:  cableRenum_Count     =====-----;;;;;


(defun cableRenum_Count (l / c l r x )

(while l
	(setq 	x (car l)
		c (length l)
		l (vl-remove x (cdr l))
		r (cons (cons x (- c (length l))) r)
	) ;setq
) ;while

(reverse r)

) ;cableRenum_Count


;**********************************    End of File     **********************************;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 14:36:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6833108#M130665</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2017-01-26T14:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6833159#M130666</link>
      <description>&lt;P&gt;I did not dig into it very much, just blind shot... looks like it is working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun cableRenum_sortList (xL)

(vl-sort xL
	'(lambda (a b)
		(or	
			(&amp;lt; 
				(atof (rtos (cadr (assoc 11 (entget (car a)))) 2 5))
				(atof (rtos (cadr (assoc 11 (entget (car b)))) 2 5))
			) ;&amp;lt; X X'

...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 14:58:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6833159#M130666</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2017-01-26T14:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6833427#M130667</link>
      <description>&lt;P&gt;It works for me!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are as awesome as ever BeekeeCZ.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 16:09:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/6833427#M130667</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2017-01-26T16:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/7012336#M130668</link>
      <description>&lt;P&gt;BeeKeeCZ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1779365"&gt;@ВeekeeCZ&lt;/a&gt;, May I ask for your assistance?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am running into the same issue once again.&amp;nbsp; See the attached drawing file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the full routine, with your addition of the (atof (rtos (....) 2 5)):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:cable_renum ( / adoc eFlag aList bList fD *error* ssBubs i8List cList cList2
			wP1 wP2 iList cTvLc tList eList i3List i4List i5List i6List i7List tVal iClist tCt tNum)

(vl-load-com)
(vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setvar "cmdecho" 0)
(setq eFlag 1 ssBubs (ssadd)
	aList (list 	"A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" 
			"N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z")
	bList (list 	"LMR" "STACKWISE"))

;***************;
(setq fD 1.25)	; fuzz distance for text alignment in cableRenum_sortList
;***************;

(defun *error* (msg)
	(if (member msg '("quit / exit abort" "Conversion failed." "*Cancel*"))
		(progn (setvar "cmdecho" 1)(vla-endundomark adoc)
			(cond
				((= eFlag 1) (princ "\n &amp;lt;!&amp;gt; Routine aborted &amp;lt;!&amp;gt; "))
				((= eFlag 2) (princ "\n &amp;lt;!&amp;gt; Cable values adjusted &amp;lt;!&amp;gt; "))
			) ;cond
		) ;progn
	) ;if
) ;*error*

(cableRenum_getReady)
(cableRenum_getAllCables wP1 wP2)
(cableRenum_idBUBREFs wP1 wP2)
(cableRenum_consolidate)
(cableRenum_parse)

(if (&amp;gt; (sslength ssBubs) 0) (command "chprop" ssBubs "" "c" "1" ""))
(setq eFlag 2)
(exit)
) ;cable_renum


;;;;;-----=====     subFunction:  cableRenum_getReady     =====-----;;;;;


(defun cableRenum_getReady ()

(if 	(not 	(and 	(princ "\n\033\n Select two points for crossing window ")
			(setq wP1 (getpoint "\n &amp;lt;.&amp;gt; Select 1st point "))
			(setq wP2 (getpoint "\n &amp;lt;.&amp;gt; Select 2nd point "))
		) ;and
	) ;not

	(progn (princ "\n Two points required ")(exit))
	(progn (command "zoom" "w" wP1 wP2)(alert " Please, wait while routine completes\n\n\n...click OK to continue "))
) ;if

) ;cableRenum_getReady


;;;;;-----=====     subFunction:  cableRenum_getAllCables     =====-----;;;;;


(defun cableRenum_getAllCables (wP1 wP2 / allC tCntr aFlag tName tVal tLen tempL)

(if (setq allC (ssget "_C" wP1 wP2 '((0 . "TEXT")(8 . "TEXT")(67 . 0))) tCntr 0)
	(while (&amp;lt; tCntr (sslength allC))
	(setq aFlag "T" tName (ssname allC tCntr) tVal (cdr (assoc 1 (entget tName))) tLen (strlen tVal))	

		(if (&amp;gt;= tLen 3)
			(progn
			(setq tempL (mapcar 'chr (vl-string-&amp;gt;list (substr tVal (- tLen 2)))))
			(foreach l tempL (if (member l aList) (setq aFlag "F")))
			(foreach b bList (if (= b (substr tVal 1 (strlen b))) (setq aFlag "F")))
			) ;progn
		) ;if

		(if	(and	(= aFlag "T")
				(&amp;gt; tLen 10)
				(wcmatch (substr tVal (- tLen 3) 1) "-")
				;(wcmatch (substr tVal (- tLen 7) 1) "-")
				(= (vl-string-search "," tVal) nil)
				(= (vl-string-search " " tVal) nil)
			) ;and	

		(setq iList (append iList (list tName)))
		) ;if

	(setq tCntr (1+ tCntr))
	) ;while

	(progn (princ "\n\033\n &amp;lt; Selection set empty &amp;gt; ")(exit))
) ;if

) ;cableRenum_getAllCables


;;;;;-----=====     subFunction:  cableRenum_idBUBREFs     =====-----;;;;;


(defun cableRenum_idBUBREFs (wP1 wP2 / ssC ssV cList vList vFlag cntrC cntrV cIpnt pt1 pt2 lpt1 lpt2 
				bFind lFind sPnt ePnt tFind)

(if (setq vFlag 0 cntrC 0 cntrV 0 ssC (ssget "_C" wP1 wP2 '((0 . "CIRCLE")(8 . "TEXT")(40 . 0.25))))
	(progn
	(setq ssV (ssget "X" '((0 . "LWPOLYLINE")(8 . "0,VIEWPORT")(67 . 0))))
	(while (&amp;lt; cntrC (sslength ssC)) (setq cList (cons (ssname ssC cntrC) cList) cntrC (1+ cntrC)))
	(while (&amp;lt; cntrV (sslength ssV)) (setq vList (cons (ssname ssV cntrV) vList) cntrV (1+ cntrV)))
	(if (= (getvar "tilemode") 0) (setvar "tilemode" 1))

		(foreach c cList
			(progn
			(setq vFlag 0 cIpnt (cdr (assoc 10 (entget c))))
			(vla-getboundingbox (vlax-ename-&amp;gt;vla-object c) 'pt1 'pt2)
			(setq 	pt1 (vlax-safearray-&amp;gt;list pt1) pt2 (vlax-safearray-&amp;gt;list pt2)
				lpt1 (list (- (car pt1) 0.025) (- (cadr pt1) 0.025))
				lpt2 (list (+ (car pt2) 0.025) (+ (cadr pt2) 0.025)))	

				(if (setq bFind (ssget "X" (list	
					'(0 . "TEXT")'(8 . "TEXT")'(67 . 0)
					'(-4 . "&amp;lt;AND")
					'(-4 . "&amp;gt;,&amp;gt;,=") (cons 10 (list (car pt1) (cadr pt1)))
					'(-4 . "&amp;lt;,&amp;lt;,=") (cons 10 (list (car pt2) (cadr pt2)))
					'(-4 . "AND&amp;gt;"))))

(foreach v vList
	(if (= vFlag 0)
		(progn
		(vla-getboundingbox (vlax-ename-&amp;gt;vla-object v) 'pt1 'pt2)
		(setq pt1 (vlax-safearray-&amp;gt;list pt1) pt2 (vlax-safearray-&amp;gt;list pt2))

			(if	(and	(&amp;gt;= (car cIpnt) (car pt1))(&amp;gt;= (cadr cIpnt) (cadr pt1))
					(&amp;lt;= (car cIpnt) (car pt2))(&amp;lt;= (cadr cIpnt) (cadr pt2)))
							
(if (setq lFind (ssget "_C" lpt1 lpt2 '((0 . "LINE")(8 . "WIRE")(67 . 0))))

	(if	(setq	sPnt (cdr (assoc 10 (entget (ssname lFind 0))))
			ePnt (cdr (assoc 11 (entget (ssname lFind 0))))
			tFind (ssget "_W" sPnt (list (car ePnt) (+ (cadr ePnt) 0.25)) 
				'((0 . "TEXT")(8 . "TEXT")(67 . 0))))
	
		(setq vFlag 1 cTvLc (cons (list
			c 
			(ssname bFind 0)
			(cdr (assoc 1 (entget (ssname bFind 0))))
			v 	
			(ssname lFind 0) 
			(ssname tFind 0)
			(cdr (assoc 1 (entget (ssname tFind 0))))) cTvLc))
	) ;if
) ;if
			) ;if
		) ;progn
	) ;if
) ;foreach
				) ;if
			) ;progn
		) ;foreach
	) ;progn
) ;if

) ;cableRenum_idBUBREFs


;;;;;-----=====     subFunction:  cableRenum_consolidate     =====-----;;;;;


(defun cableRenum_consolidate ( / zList rFlag cVal)

(foreach c cTvLc (setq zList (cons (list (nth 5 c) (nth 1 c)) zList)))

(foreach iL iList
	(progn
	(setq rFlag "F" cVal (cdr (assoc 1 (entget iL))))
	(foreach z zList (if (equal iL (car z)) (setq rFlag "T")))
	(if (= rFlag "F") (setq i3List (cons (list iL) i3List)))

		(if (= (member (list (substr cVal 1 (- (strlen cVal) 3))) tList) nil)
		(setq tList (cons (list (substr cVal 1 (- (strlen cVal) 3))) tList))
		) ;if
	) ;progn
) ;foreach

(foreach z zList
	(setq 	i4List (cons (list 
				(nth 0 z)
				(cdr (assoc 1 (entget (nth 0 z))))
				(cdr (assoc 1 (entget (nth 1 z))))) i4List)
		i7List (cons (cdr (assoc 1 (entget (nth 1 z)))) i7List)
	) ;setq
) ;foreach

(setq 	i7List (cableRenum_Count i7List)
	eList (append i3List i4List)
 	tList (vl-sort tList '(lambda (x y) (&amp;lt; (car x) (car y)))))

) ;cableRenum_consolidate


;;;;;-----=====     subFunction:  cableRenum_parse     =====-----;;;;;


(defun cableRenum_parse ( / tCt sCntr sCntr3 tRlist tSlist tTlist tUlist tVlist tUlen i7len i8List tUl itQA sCntr2)

(foreach t1 tList			
	(progn
	(setq sCntr 0 tSlist () i5List () tRlist () i8List ())
		(foreach e1 eList
			(if	(and	(not (= eList nil))
					(not (= e1 nil))
					(equal  
						(substr 
							(cdr (assoc 1 (entget (car e1)))) 
							1 
							(- (strlen (cdr (assoc 1 (entget (car e1))))) 3)
						) ;substr
						(car t1)
					) ;equal
				) ;and

				(progn
				(cableRenum_PnI)
				(cableRenum_increase)
				) ;progn
			) ;if
		) ;foreach
	) ;progn
) ;foreach

) ;cableRenum_parse


;;;;;-----=====     subFunction:  cableRenum_PnI     =====-----;;;;;


(defun cableRenum_PnI ( / )

(if (= (member e1 i4List) nil)
	(setq i8List (cons e1 i8List))

	(progn
	(setq 	tTlist () tUlist () tVlist () 
		itQA 0
		sCntr3 0 
		i4List (vl-sort i4List '(lambda (x y) (&amp;lt; (caddr x) (caddr y)))))

		(while (&amp;lt; sCntr (length i4List))
			(foreach i7 i7List		; find QAs of BUBREFs
			(if (= (caddr (nth sCntr i4List)) (car i7)) (setq itQA (cdr i7)))
			) ;foreach

		(setq tRlist () sCntr2 0 titQA (+ itQA sCntr3))

			(while (&amp;lt; sCntr3 titQA)
			(setq 	tRlist (append tRlist (list (nth sCntr3 i4List)))
				sCntr3 (1+ sCntr3))
			) ;while

			(setq 	tSlist (cableRenum_sortList tRlist) 
				sCntr (+ sCntr itQA) 
				sCntr2 0
				tTlist (append tTlist (list tSlist))
			) ;setq

			(foreach tT tTlist
				(progn
				(setq tUlist ())
					(foreach ta tT
						(setq tUlist 
							(append tUlist 
								(list (car ta))
							) ;append
						) ;setq
					) ;foreach
				(setq tVlist (append tVlist (list tUlist)))
				) ;progn
			) ;foreach					
		) ;while

		(setq tSlist tTlist)

	(setq i7len (length i7List) tRlist ())

		(while (&amp;gt; i7len 0)
			(setq 	tRlist (cons (last tVlist) tRlist)
				tVlist (vl-remove (last tVlist) tVlist)
				i7len (1- i7len)
			) ;setq
		) ;while

		(foreach tS tSlist
			(if (or (= (length tS) 1)(&amp;gt; (length tS) 2))
			(foreach ta tS (setq ssBubs (ssadd (car ta) ssBubs)))
			) ;if
		) ;foreach

	(setq i5List tRlist)
	) ;progn
) ;if

) ;cableRenum_PnI


;;;;;-----=====     subFunction:  cableRenum_increase     =====-----;;;;;


(defun cableRenum_increase ( / )

(setq tCt 1 i6List (cableRenum_sortList (append i8List i5List)))

(foreach i6 i6List
	(progn
		(foreach ia i6
			(progn
				(setq	tL (entget ia) 
					tNum (cond ((= (strlen (itoa tCt)) 1) (strcat "00" (itoa tCt)))
						   ((= (strlen (itoa tCt)) 2) (strcat "0" (itoa tCt)))
						   ((= (strlen (itoa tCt)) 3) (itoa tCt)))
					tVal (strcat (car t1) tNum)
					tL (subst (cons 1 tVal) (assoc 1 tL) tL)
				) ;setq
			(entmod tL)
			) ;progn
		) ;foreach

	(setq tCt (1+ tCt))
	) ;progn
) ;foreach

) ;cableRenum_increase


;;;;;-----=====     subFunction:  cableRenum_sortList     =====-----;;;;;


(defun cableRenum_sortList (xL)

(vl-sort xL
	'(lambda (a b)
		(or	
			(&amp;lt; 
				(atof (rtos (cadr (assoc 11 (entget (car a)))) 2 5))
				(atof (rtos (cadr (assoc 11 (entget (car b)))) 2 5))
			) ;&amp;lt; X X'

			(and	
				(equal 
					(cadr (assoc 11 (entget (car a))))
					(cadr (assoc 11 (entget (car b))))
				fD) ;equal X X'

				(&amp;gt; 
					(caddr (assoc 11 (entget (car a)))) 
					(caddr (assoc 11 (entget (car b))))
				) ;&amp;gt; Y Y'
			) ;and
		) ;or
	) ;lambda
) ;vl-sort

) ;cableRenum_sortList


;;;;;-----=====     subFunction:  cableRenum_Count     =====-----;;;;;


(defun cableRenum_Count (l / c l r x )

(while l
	(setq 	x (car l)
		c (length l)
		l (vl-remove x (cdr l))
		r (cons (cons x (- c (length l))) r)
	) ;setq
) ;while

(reverse r)

) ;cableRenum_Count&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is difference between the two columns of cable numbers?&amp;nbsp; The column on the left renumbers appropriately while the column on the right does not.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 14:44:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/7012336#M130668</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2017-04-12T14:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/7012555#M130669</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;I did the same thing as before with the other comparisons as well, lower the precision and it works...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun cableRenum_sortList (xL)
  
  (vl-sort xL
           '(lambda (a b)
              (or
                (&amp;lt;
                  (atof (rtos (cadr (assoc 11 (entget (car a)))) 2 1))
                  (atof (rtos (cadr (assoc 11 (entget (car b)))) 2 1))
                  ) ;&amp;lt; X X'
                
                (and
                  (equal
                    (atof (rtos (cadr (assoc 11 (entget (car a)))) 2 1))
                    (atof (rtos (cadr (assoc 11 (entget (car b)))) 2 1))
                    fD) ;equal X X'
                  
                  (&amp;gt;
                    (atof (rtos (caddr (assoc 11 (entget (car a)))) 2 1))
                    (atof (rtos (caddr (assoc 11 (entget (car b)))) 2 1))
                    ) ;&amp;gt; Y Y'
                  ) ;and
                ) ;or
              ) ;lambda
           ) ;vl-sort
  
  ) ;cableRenum_sortList&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Apr 2017 15:49:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/7012555#M130669</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2017-04-12T15:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/7013265#M130670</link>
      <description>&lt;P&gt;Thank you for the response, BeeKeeCZ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It worked on the test file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I went back to 'real' file and it didn't work &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 20:21:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/7013265#M130670</guid>
      <dc:creator>zph</dc:creator>
      <dc:date>2017-04-12T20:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Sort help</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/7014212#M130671</link>
      <description>&lt;P&gt;Have you tried trace the process to see where it fails? Step by step. Do you know how to do that?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://knowledge.autodesk.com/community/screencast/d8eb1c73-abdd-46bb-8a7c-e71fb7e12e29" target="_self"&gt;HERE&lt;/A&gt;&amp;nbsp;is a simple example how it works.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 08:06:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/sort-help/m-p/7014212#M130671</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2017-04-13T08:06:03Z</dc:date>
    </item>
  </channel>
</rss>

