Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to write a function that will get a selection of blocks, and then return a list of the blocks sorted by insertion x,y (left to right, top to bottom).
(defun c:exp1 (/ ss i lst en)
(if (setq ss (ssget))
(progn (repeat (setq i (sslength ss))
(setq en (ssname ss (setq i (1- i)))
lst (cons (cons en (cdr (assoc 10 (entget en)))) lst))
)
(setq s_lst (vl-sort lst '(lambda (x y) (if (= (car x) (car y)) (> (cadr x) (cadr y)) (< (car x) (car y))))))
)
)
(princ)
)
I'm trying to make it so that s_lst is the final sorted list. When I run the script it returns error "bad argument type for compare: <Entity name: 1fa972769b0> <Entity name: 1fa97276a90>". I think it must have something to do with the lambda sorting function but I'm not sure.
I have done some searching and i'm getting pretty close close (I can sort by X coordinate only). See below for working X-coordinate sort.
(defun c:exp1 (/ ss i lst en)
(if (setq ss (ssget))
(progn (repeat (setq i (sslength ss))
(setq en (ssname ss (setq i (1- i)))
lst (cons (cons en (cdr (assoc 10 (entget en)))) lst))
)
(mapcar 'print (vl-sort lst ''((a b) (< (cadr a) (cadr b)))))
)
)
(princ)
)
Thanks,
Solved! Go to Solution.