Draw polylines between multiple blocks

Draw polylines between multiple blocks

Anonymous
Not applicable
2,398 Views
4 Replies
Message 1 of 5

Draw polylines between multiple blocks

Anonymous
Not applicable

Hello,

 

I'm having troubles with finding the LISP routine I need.

I have found a LISP which creates a lwpolyline between two selected blocks, works perfect, but i want to modify it so I can select multiple blocks and let Autocad draw a polyline between them. I want to select one block as a base, and then select other blocks to draw (lw)polylines to.

 

This is the LISP I want to expand:

 

(defun c:l2b (/ ss)
  (if (and (setq ss (ssget '((0 . "INSERT")))) (eq (sslength ss) 2))
    (entmakex (list '(0 . "LWPOLYLINE")
                    '(100 . "AcDbEntity")
                    '(100 . "AcDbPolyline")
                    '(90 . 2)
                    (assoc 10 (entget (ssname ss 0)))
                    (assoc 10 (entget (ssname ss 1)))
                    (assoc 210 (entget (ssname ss 1)))
              )
    )
  )
  (princ)
)

Side node: I don't have any experience with programming in AutoCAD..

 

 

Any Help is appreciated.

 

Kind regards,

Martijn

0 Likes
Accepted solutions (1)
2,399 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

You want to connect one base block to all others, right?

 

(defun c:ConnBlocks (/ base ss i)

  (if (and (setq base (car (entsel "\nSelect base block: ")))
	   (or (= "INSERT" (cdr (assoc 0 (entget base))))
	       (prompt "\nWrong selection, not a block."))
	   (setq base (cdr (assoc 10 (entget base))))
	   (princ "\n...and blocks to connect to, ")
	   (setq ss (ssget '((0 . "INSERT"))))
	   )
    (repeat (setq i (sslength ss))
      (command "_.PLINE"
	       "_none" (trans base 0 1)
	       "_none" (trans (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))) 0 1)
	       "")))
  (princ)
)
Message 3 of 5

Anonymous
Not applicable

Perfect! That's excactly what I needed!

 

Tanks!

0 Likes
Message 4 of 5

Anonymous
Not applicable

Hi,

Found that LISP and it's eprfect for my usage!

 

Only one thing:

is it possible to draw the pline from base point of the original block to an endpoint from the 2nd block?

 

Thanks!

0 Likes
Message 5 of 5

ВeekeeCZ
Consultant
Consultant

Hi @Anonymous, glad you found it useful. And welcome to these forums!

 

The point is that the routine connects blocks by its insertions point. Blocks insertion point is the only point that we can receive from a block automatically and easily. If you need find some other point (you may cool it 'endpoint') we need to find some other method, more complicated, less reliable - maybe using osnaps or bounding box... depends on the real shape of your block/blocks.

 

So I recommend you to create a new topic upon this subject and attach some DWG with examples of your block(s) and the way to connect them. If a solution will not be to much complicated, me or someone else here would provide you some solution with pleasure!