I'm having trouble sorting an entity list by insertion point y-value. We have rows of blocks that are typically separated by 20' or so but sometimes adjacent rows can only be a few feet different in y-value. Within each row the blocks can have y-values that can differ by as much as 1'. I have a list of entities that I want to sort so that all similar y-values (within a 12" fuzz factor) are placed into a separate list from largest to smallest. The final list would look something like: ((ent1 ent3 ent4) (ent2 ent5 ent6) (ent7 ent8)). Entities 3 & 4 would have insertion points within 12" of entity 1. The entity 2 insertion point would be further than 12" from entity 1 and entities 5 & 6 would have insertion points within 12" of entity 2, and so on. The first instance of any block that has an insertion point greater than 12" from a previous value can be used as a new base for comparison. Each sublist would represent a row of blocks that have insertion points with y-values within 12" of each other. The posted code will create the entity list for the attached example drawing. The example should produce a list of 4 sublists.
blk:l - (ent1 ent2 ent3 ...)
yval:l - ((ent1 ent3 ent4) (ent2 ent5 ent6) (ent7 ent8))
take first item in blk:l
get y-val & put in yval:l
take next item in blk:l
get y-val & compare to yval:l
if within 12" of any first subitem in yval:l (in list above only compare to ent1 ent2 ent7)
add to subitem
else create new subitem
(defun C:SORTTEST
(/ pt1 pt2 selset
) pt1
pt2
'((0 . "INSERT") (2 . "test"))
) ;_ end of ssget
blk:l
(UTIL:SELSET
->LIST selset
nil) ) ;_ end of setq
;; sort list sort:l here
) ;_ end of defun
(defun UTIL:SELSET
->LIST (selset entorobj
/ cnt sslist
) ) ;_ end of repeat
(if (= "OBJECT" entorobj
) ) ;_ end of if
sslist
)