Some quick code / food for thought:
PicksetToObjects:
(defun _PicksetToObjects ( ss )
[color=green];; Convert a pickset (selection set) to a list of objects.[/color]
(if (eq 'pickset (type ss))
(mapcar
(function (lambda (x) (vlax-ename->vla-object (cadr x))))
(vl-remove-if (function (lambda (x) (minusp (car x)))) (ssnamex ss))
)
)
)
SortObjects:
(defun _SortObjects ( objects foo )
[color=green];; Sort the objects using function foo, which takes two
;; arguments, both objects. What foo does we don't care,
;; our job is to invoke it if it's defined. Note: define
;; foo using the (function (lambda (a b) ...)) form. If
;; foo is not defined sort the objects by the ObjectIDs.[/color]
(vl-sort objects
(if [color=red]foo foo[/color]
(function
(lambda (a b)
(<
(vla-get-objectid a)
(vla-get-objectid b)
)
)
)
)
)
)
Demo:
(if (setq objects ([color=red]_PicksetToObjects[/color] (ssget)))
(progn
(princ "\n\nObjectIDs for the unsorted list:")
(print (mapcar 'vla-get-objectid objects))
(princ "\n\nObjectIDs for the sorted list, default algorythm:")
(print (mapcar 'vla-get-objectid ([color=red]_SortObjects[/color] objects nil)))
(princ "\n\nObjectIDs for the sorted list, custom algorythm:")
(print
(mapcar 'vla-get-objectid
([color=red]_SortObjects[/color] objects
(function
(lambda (a b)
(<
(vla-get-objectname a)
(vla-get-objectname b)
)
)
)
)
)
)
(princ)
)
)
Output:
ObjectIDs for the unsorted list:
(51 50 49 48 46 43 52 53 54 55 56 57 58 59 60)
ObjectIDs for the sorted list, default algorithm:
(43 46 48 49 50 51 52 53 54 55 56 57 58 59 60)
ObjectIDs for the sorted list, custom algorithm:
(54 55 59 56 43 51 50 49 48 46 57 52 53 60 58)