Align existing blocks into same line

Align existing blocks into same line

gSedusak
Explorer Explorer
765 Views
7 Replies
Message 1 of 8

Align existing blocks into same line

gSedusak
Explorer
Explorer

Hi, dear AutoCAD experts.

I always found a solution on this forum, but it seams nobody had this situation.

I usually have large number of different blocks placed on drawing. I have to rearrange those blocks into single line with (usually) same distance between them.

This is screenshot of the drawing i get:

situation1.jpg

 

And this is drawing, that I have to make.

situation2.jpg

 

The most perfect solution would be, that I could align blocks into single line with lines connected from one to another (then I can arrange them into rows fast), or to align them into single line with fixed distance between them, and then I will do the adjustments for those blocks, that have more text in attributes.

 

For now, I'm using two sets of blocks (one without line and one with lines), then I make BLOCKREPLACE command, to transform them, and then I rearrange them manually into lines.

 

Best regards, Gašper

 

0 Likes
766 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

A good starting basis would be BlockChart-Rows.lsp, >here<.  It has some differences:  It goes for drawing files in a folder rather than Blocks in the current drawing, and [you may prefer this one] it limits its row length to the width of the drawing limits, and it doesn't draw Lines between -- all that could be adjusted easily enough.  But it spaces things with equal-size gaps between [horizontally as well as vertically if it goes to more than one row].

 

Does the order of them matter?  If so, what would be the criteria for ordering them?

Kent Cooper, AIA
0 Likes
Message 3 of 8

calderg1000
Mentor
Mentor

Regards @gSedusak 

Try this code...

(defun c:mbd (/ p s i sn sdx pt)
  (setq p (getpoint "\nPick Point: ")
        d (getdist "\nEnter Distance:")
        s (ssget '((0 . "insert")))
  )
  (repeat (setq i (sslength s))
    (setq sn  (ssname s (setq i (1- i)))
          sdx (entmod (subst (cons 10 p) (assoc 10 (entget sn)) (entget sn)))
          p   (mapcar '+ p (list d 0. 0.))
    )
  )
)

 

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 4 of 8

Sea-Haven
Mentor
Mentor

calderg1000 very nice, the thing I am worried about is how the blocks are ordered or is random Ok. Need Gsedusak to confirm. If an order is required then I can only see pick pick.

0 Likes
Message 5 of 8

gSedusak
Explorer
Explorer

Thank you all for the replies. Today I tested both @Kent1Cooper solution and your solution. 

Your code works almost perfectly, it is exactly what I need, because blocks can be in random order.

The only issue I have with your code, that blocks attributes don't move, but they stay in original position.

If you find me the solution for moving the attributes with blocks, that would be perfect.

 

Regards, Gašper

 

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant

@gSedusak wrote:

.... blocks attributes don't move, but they stay in original position. ....


[I would guess that if the Blocks are relocated using a MOVE command, instead of by (entmod)ing their insertion points, the Attributes will go along.]

Kent Cooper, AIA
0 Likes
Message 8 of 8

Kent1Cooper
Consultant
Consultant

@gSedusak wrote:

.... I have to rearrange those blocks into single line with (usually) same distance between them.

.... The most perfect solution would be, that I could align blocks into single line with lines connected from one to another ..., or to align them into single line with fixed distance between them....


Perhaps this?

;|BlocksInRow.lsp [command name: BIR]
Puts all selected Blocks In a Row, starting at a User-specified location, placing
them with their insertion points horizontally aligned, with equal-sized gaps
between their extents in the horizontal direction, and with Lines on current
Layer connecting their insertion points.
Space between extents of Blocks is in 'space' variable [see EDIT note below].
Kent Cooper, 7 June 2023
|;
(vl-load-com)
(defun C:BIR (/ ss space nextleft blk blkLL blkUR blkleft blkins lastins)
  (if (setq ss (ssget "_:L" '((0 . "INSERT")))); Blocks not on locked Layers
    (progn ; then
      (setq
        space 1 ; dwg units between blocks <------ EDIT: set as desired
        nextleft (getpoint "\nLeft edge of first Block at Y-coordinate level of insertion point: ")
      ); setq
      (repeat (setq n (sslength ss))
        (setq blk (ssname ss (setq n (1- n))))
        (vla-getboundingbox (vlax-ename->vla-object blk) 'minpt 'maxpt)
        (setq
          blkLL (vlax-safearray->list minpt)
          blkUR (vlax-safearray->list maxpt)
          blkleft (list (car blkLL) (caddr (assoc 10 (entget blk)))); left edge at Y coord. of ins. pt.
        ); setq
        (command "_.move" blk "" "_non" blkleft "_non" nextleft)
        (setq blkins (cdr (assoc 10 (entget blk)))); in new location
        (if lastins
          (command "_.line" "_non" lastins "_non" (setq lastins blkins) ""); then
          (setq lastins blkins); else
        ); if
        (setq nextleft (polar nextleft 0 (+ (- (car blkUR) (car blkLL)) space)))
      ); repeat
    ); progn
  ); if
  (prin1)
); defun

Lightly tested.  Attributes do go along. 

Kent Cooper, AIA
0 Likes