@kpennell wrote:
....
The resulting retuning code is:
(sort_num (list '(1 ename1) '(3 ename3) '(2 ename2) '(4 ename4)))
and what gets returned is sorted correctly.
I would have thought that I could use:
(setq EntName (cdr (nth 0 sort_num)))
to select the entity ....
If 'ename1' etc. are variables holding entity names, they can't be in "quoted" lists [with the apostrophe prefix], because the variable requires evaluation [read about the (quote) and (list) functions in Help]. I think you would need to have:
(sort_num (list (list 1 ename1) (list 3 ename3) (list 2 ename2) (list 4 ename4)))
But correcting that if necessary [maybe they really are <entity names>], then try:
(setq EntName (cadr (nth 0 sort_num)))
The way you have it, what will be returned is a one-item list, containing the entity name, not the entity name itself. The (cdr) function returns the item itself, not in a list, from a dotted-pair list, such as an entity name in (assoc 0) from an entity data list, Layer name from (assoc 8), etc., but dotted-pair lists are handled differently in that regard -- yours is a list of "ordinary" lists.
Oh, but wait.... Is sort_num a function, or a variable name? If you're going to use it in (nth 0 sort_num), it looks like a variable name, holding a list, and you should have something like:
(setq sort_num (list (list 1 ename1) (list 3 ename3) (list 2 ename2) (list 4 ename4)))
But if it's a function as the first line of code suggests, then getting something from it would need to be something more like:
(setq EntName (cadr (nth 0 (sort_num (list..... )))))
or you should use another variable:
(setq sortedlist (sort_num (list (list 1 ename1) (list 3 ename3) (list 2 ename2) (list 4 ename4))))
... and later ...
(setq EntName (cadr (nth 0 sortedlist)))
Kent Cooper, AIA