ARRANGE BLOCKS BY SELECTION ORDER

ARRANGE BLOCKS BY SELECTION ORDER

atawk
Enthusiast Enthusiast
3,858 Views
24 Replies
Message 1 of 25

ARRANGE BLOCKS BY SELECTION ORDER

atawk
Enthusiast
Enthusiast

is there a lisp to arrange blocks by selection order, (see attached image).

e.g.: the example below shows at the left some randomly distributed blocks where we need to rearrange them by "selection order" from 1 to 6 as shown on the right image. 

 

atawk_0-1643891320115.png

 

0 Likes
Accepted solutions (2)
3,859 Views
24 Replies
Replies (24)
Message 2 of 25

ВeekeeCZ
Consultant
Consultant

Post a dwg!

How would you specify the order? By manual selection, or by numbers? Are they real blocks or just examples? Are those numbers attributes?

0 Likes
Message 3 of 25

atawk
Enthusiast
Enthusiast

I will specify the order by manual selection. These are blocks regardless the numbers or attributes that were mentioned just to clarify the sort order. 

What we want is to select blocks manually click by click and then rearrange them as per selection.

0 Likes
Message 4 of 25

ВeekeeCZ
Consultant
Consultant

Ok... but rearrange how... Put them in line by their insertion points? (same Y coord).

Delta X (between insertion points) specified by a user?

0 Likes
Message 5 of 25

atawk
Enthusiast
Enthusiast

We want to rearrange them from left to right on the X direction as shown in the first attached image. 

First block selected will be the first to the left and the last block selected will be the last to the left while the others will fit in the middle between the first and the last by selection order. 

0 Likes
Message 6 of 25

ВeekeeCZ
Consultant
Consultant

Not answering my questions.

Are all the selected blocks same/similar geometry? 

0 Likes
Message 7 of 25

atawk
Enthusiast
Enthusiast

The selected blocks are not similar geometry nor similar names. 

0 Likes
Message 8 of 25

Kent1Cooper
Consultant
Consultant

@atawk wrote:

The selected blocks are not similar geometry nor similar names. 


So the spacing / relative positions will need to be determined by the size of each Block as it goes along?

Kent Cooper, AIA
0 Likes
Message 9 of 25

atawk
Enthusiast
Enthusiast

Yes

0 Likes
Message 10 of 25

ВeekeeCZ
Consultant
Consultant
Accepted solution

Let's see if this will work for you.

 

(defun c:BInLine ( / s p v a d i n)

  (if (and (setq s (ssget "_:L" '((0 . "INSERT"))))
	   (vl-cmdf "_.move" (ssname s 0) "" "_non" (trans (cdr (assoc 10 (entget (ssname s 0)))) 0 1) pause)
	   (setq p (getvar 'lastpoint))
	   (setq v (getpoint p "\nSpecify vector: "))
	   (setq a (angle (trans p 1 0) (trans v 1 0)))
	   (setq d (distance p v))
	   (setq p (trans p 1 0))
	   (setq i 0)
	   )
    (repeat (1- (sslength s))
      (setq e (entget (ssname s (setq i (1+ i)))))
      (setq n (polar p a (* i d)))
      (entmod (append e
		      (list (cons 10 n))))))
  (princ)
  )

 

Message 11 of 25

Kent1Cooper
Consultant
Consultant

@atawk wrote:

Yes


A good start on the spacing part will be found in BlockChart.lsp, >here<.  It pulls them from a folder, but the same approach to that aspect would work under selection in a drawing.

Kent Cooper, AIA
0 Likes
Message 12 of 25

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

Let's see if this will work for you...


That was quick, i was still reading through the other posts.... 🙂

 

Message 13 of 25

pendean
Community Legend
Community Legend
0 Likes
Message 14 of 25

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ's routine spaces the Blocks' insertion points equally, at your specified spacing, so if you choose something that's not as wide as the widest Block, or if any Blocks' insertion point locations vary a lot in their relation to the drawn content, you can end up with Blocks overlapping, or larger spaces between them than you probably want, and even large variability from being [visually] in a "row."  It also allows selection by means [e.g. Window, Crossing, Lasso, Last] that are without control over the order it will use to place them [involving drawn order in some way].

 

@pendean's linked routine apparently [I only watched the video, but didn't try it] aligns things, but keeps them in their sequence, not your selected order, and either doesn't change the horizontal spacing or if equal spacing is chosen, bases it on the existing spacing between the extreme objects in the selection.

 

So I offer something that I think is more in line with your request, the attached EntityRow.lsp with its ERow command.  It uses the actual size [extents] of each object, not Block insertion points, to establish the position of each in its Moved location relative to the previous Moved object [or relative to the start-of-row location for the first one].  Because it's based on extents rather than insertion points, it can be used for any object type(s), not just Blocks [hence the name with Entity, not Block].  And it requires you to pick things in ways that are clear about the sequence you want [individual picks or Fence], ignoring things selected by other means [and scolding you for it].  See more commentary at the top of the file.

 

[It could be edited to ask for the 'gap' variable value, rather than have it built in.  And it could have an Undo Begin/End wrapper, and if so, an *error* handler would also be appropriate.]

Kent Cooper, AIA
Message 15 of 25

atawk
Enthusiast
Enthusiast

when selecting object using windows selection it returns nothing. only the objects selected by picking are returned. can you update it please to return any kind of selection. 

0 Likes
Message 16 of 25

pbejse
Mentor
Mentor

@atawk wrote:

is there a lisp to arrange blocks by selection order, (see attached image).

...


 

(Defun c:side ( / pdata moveTo inc ss first objpoints startpoint)
(defun pdata (obj / ObjLl ObjUr)
  (vla-GetBoundingBox obj 'ObjLl 'ObjUr
  )
  (mapcar '(lambda (d)
	     (safearray-value d))
	  (list ObjLl ObjUr)
  )
)
    
(defun moveTo (obj fp lst)
  (Vlax-invoke obj 'Move (car lst) fp)
  (list (- (car fp) (- (caadr lst)) (caar lst))
  	(cadr fp) 0.0)
  
)
    
  (if (And
	(setq inc 0
	      ss (ssget "_:L" '((0 . "INSERT"))))
	(setq first (vlax-ename->vla-object (ssname ss inc)))
	(setq objpoints (pdata first))
	(setq startpoint (getpoint (car objpoints) "\Pick start location"))
	)
    (progn
      (setq startpoint (moveTo  first startpoint objpoints))		
      (repeat (1- (sslength ss))
	(setq next (vlax-ename->vla-object (ssname ss (setq inc (1+ inc)))))
	(setq startpoint (moveTo next startpoint (pdata next)))
	)
      )
    )
(princ)
)

 

 

HTH

 

Message 17 of 25

atawk
Enthusiast
Enthusiast

it's not working. 

0 Likes
Message 18 of 25

pbejse
Mentor
Mentor
Accepted solution

@atawk wrote:

it's not working. 


I'ts working here fine @atawk 
Make sure you copy the file correctly from the code tags.

or am i missing something here. or even misunderstood the request.

 

Let me know how it goes

 

 

0 Likes
Message 19 of 25

Kent1Cooper
Consultant
Consultant

@atawk wrote:

when selecting object using windows selection it returns nothing. only the objects selected by picking are returned. can you update it please to return any kind of selection. 


The former is exactly as in your description in Message 3 [plus the option to use Fence selection which also puts selected things into the set in the order that the Fence crosses them].  The latter is a violation of that description.  But if the order doesn't matter, the whole thing is simpler -- try the attached EntityRow2.lsp.  I left the same ERow command name, so if you would sometimes want the order to matter and sometimes not, needing both versions available in the same drawing, change one of the command names.

Kent Cooper, AIA
0 Likes
Message 20 of 25

atawk
Enthusiast
Enthusiast

Sorry for misunderstanding, the order is still matter what i meant is when i select an object using window it doesn't sort out at end with the blocks arrangement. 

0 Likes