LISP for arranging blocks and set distance

LISP for arranging blocks and set distance

gSedusak
Explorer Explorer
932 Views
3 Replies
Message 1 of 4

LISP for arranging blocks and set distance

gSedusak
Explorer
Explorer

Hello to everyone. I would need a little help from experts 😄

Some time ago, @Kent1Cooper helped me to write this LISP, so I can arrange large number off different blocks to single line:

 

From this,

gSedusak_0-1713451084325.png

 to this, with just one command. 

gSedusak_1-1713451130008.png

 

;|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.
; Space between extents of Blocks is entered by the user.
; Kent Cooper, 7 June 2023
|;

(vl-load-com)

(defun C:BIR (/ ss space nextleft blk blkLL blkUR blkleft blkins)
  ; Check if any blocks are selected on unlocked layers
  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (progn ; If blocks are selected, proceed
      (setq
        nextleft (getpoint "\nLeft edge of first Block at Y-coordinate level of insertion point: ")
        space (getdist "\nEnter the distance between blocks: ") ; Prompt for the distance between blocks
      ); setq

      ; Iterate over each selected block
      (repeat (setq n (sslength ss))
        (setq blk (ssname ss (setq n (1- n))))

        ; Get the bounding box of the block
        (vla-getboundingbox (vlax-ename->vla-object blk) 'minpt 'maxpt)

        ; Extracting the coordinates of the lower-left corner and upper-right corner of the block
        (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

        ; Move the block to the next position
        (command "_.move" blk "" "_non" blkleft "_non" nextleft)

        ; Calculate the next left edge position for the next block
        (setq nextleft (polar nextleft 0 (+ (- (car blkUR) (car blkLL)) space)))
      ); repeat
    ); progn
  ); if

  ; Print the result
  (prin1)
); defun

 

Thank you for that, that really was live safer, because sometimes i have 1000 blocks, that I need to arrange them in rows.

But now i got a new problem. Now I am using attributes and because off the attributes, the line doesn't get to the next block any more:

gSedusak_2-1713451470768.png

 

So my idea is, that i make all my blocks dynamic and make my connecting line stretching:

gSedusak_3-1713451803967.png

 

 

Now, I would need a LISP, that would arrange selected blocks to row and will connect my line to next block. My parameter for extending connecting line is "Distance1".

And I have a Visibility parameter to, so that original block doesn't have connecting line, then I switch visibility to use block for row drawing. But I will just make sure, that all blocks have same Visibility parameters and change them by hand.

 

I only made one block for now, but after I have a solution, I will make sure to make all my blocks with right parameters.

 

Thanks in advance, Gašper 

 

933 Views
3 Replies
Replies (3)
Message 2 of 4

7598165
Advocate
Advocate

please upload sample dwg

0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant

Here's a wacky idea:  Define the Attribute as starting with a default of %%O [that's a letter "O", not a zero], which is the trigger for OVERSCORE, and a space to pull the rest of the content rightward a little.  Here, I did that, and for each Attribute value, retained the "%%O " beginning, and added a space at the end.  Then the regular BIR command, unaltered, with the spacing-between at zero, turned the upper part of this image to the lower part.

Kent1Cooper_0-1713461547805.png

Then the "line" is just the overscoring of the Attribute text, self-adjusting to the length of that, and you don't need an actual Line nor the dynamic business at all.  You just have to have in mind to keep the %%O Overscoring trigger and the spaces before and after the actual content [or don't keep the spaces, if you don't mind the text crunching up closer to other parts].

 

It does take a little care in positioning the Attribute so that the end of its overscoring lands in the right place -- you can't Osnap to that, even if the justification is Top Left.

Kent Cooper, AIA
0 Likes
Message 4 of 4

gSedusak
Explorer
Explorer

Thank you both for a quick replay.

@7598165 Example file uploaded. The "Original placement"  is exactly how I get blocks arranged on a floor plan. The first result is made with LISP that is attached in this post. Wanted result is copied first result and then fixed connections with hand.

 

@Kent1Cooper This really is wacky idea 😀. I tried your solution and it worked really good.

But I really gave wrong example, how things look in reality. Unfortionally blocks are pre-designed and have attributes on both side and on the top center and so on. I made an example drawing, to make it more clear. This are most used blocks, in my library it is around 100 of them, different shapes and with different attributes.

gSedusak_0-1713468290728.png

 

Best regards, Gašper

0 Likes