Selection Set in Order Left to Right, Top to Bottom

Selection Set in Order Left to Right, Top to Bottom

Anonymous
Not applicable
2,691 Views
2 Replies
Message 1 of 3

Selection Set in Order Left to Right, Top to Bottom

Anonymous
Not applicable

There are times when i'd like to label objects such as rectangles that are in a grid. They might have 10 columns and 5 rows, etc. At any rate, I need to label them from Left to Right, and from Top to Bottom.....so Row 1 first, then Row 2, etc. However, when I use ssget to select them....it seems to be arbitrary which objects are where within the selection set list. (perhaps it does it by when each object was created?)

 

At any rate....is it possible to ssget....select all with a bounding box....then reorder the resulting selection set list by coordinates such that it is now ordered correctly? That would then make labeling it a breeze as you could just step through the list one at a time.

 

I'm thinking I could compare one vertice of one object to another and rank it somehow.....seems unwieldy. Do you experienced people have a better idea? 

0 Likes
Accepted solutions (2)
2,692 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant
Accepted solution

No. Not with window selection. Only possible way to keep the order is the fence option (ssget "_F").

 

In your case, I would suggest to make a regular window selection, then get the middle point of bounding box of every rectange (see the sub), make a list of all midpnts, then use sort them by x or y coord, as you wish, using the (vl-sort) function, see HERE, use the second example. Good luck. If you get stuck, let know.

 

 (defun MidPntOfBoundingBox (ent / obj llp urp)
    (if (and (setq obj (vlax-ename->vla-object ent))
	     (vlax-method-applicable-p obj 'getboundingbox)
	     (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp))))
	     )
      (mapcar '(lambda (a b) (/ (+ a b) 2.)) (vlax-safearray->list llp) (vlax-safearray->list urp))))
0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

There is a way around this and that is to use a double sort on the say the lower left corner of each object. You would make a list of all corners with sub list of (X Y Entity) then sort on X Y. If its an object in a grid type layout then use the "Bounding Box" method to get the lower left corner. 

 

; sorts on 1st two items
(setq lst (vl-sort lst '(lambda (x y)
(cond
((= (cadr x)(cadr y))
(< (car x)(car y)))
((< (cadr x)(cadr y)))
))))

 

 

 

 

0 Likes