draw polyline between 2 blocks

draw polyline between 2 blocks

atawk
Enthusiast Enthusiast
1,892 Views
6 Replies
Message 1 of 7

draw polyline between 2 blocks

atawk
Enthusiast
Enthusiast

I want a lisp that does the following: 

 

1. select block1 with basepoint pt1 

2. select block2 with basepoint pt2

3. draw a polyline between pt1 and pt2

0 Likes
Accepted solutions (1)
1,893 Views
6 Replies
Replies (6)
Message 2 of 7

dlanorh
Advisor
Advisor
Accepted solution

Try this.

 

(defun c:jbp (/ _get_ent _em_lwp p1 p2)

  (defun _get_ent (msg / r j h)
    (while (not h)
      (setq r (car (entsel (strcat "\nSelect " msg " Block : "))))
      (if (= (cdr (assoc 0 (setq j (entget r)))) "INSERT") (setq h (cdr (assoc 10 j))) (alert "Not a Block"))
    );end_while
    h
  );end_defun

(defun _em_lwp (lst)
  (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length lst)))
                    (mapcar '(lambda ( x ) (cons 10 x)) lst)
            );end_append
  );end_entmakex
);end_defun

  (setq p1 (_get_ent "First")
        p2 (_get_ent "Second")
  );end_setq
  (_em_lwp (list p1 p2))
  (princ)
);end_defun

 

I am not one of the robots you're looking for

Message 3 of 7

Kent1Cooper
Consultant
Consultant

How about something a little simpler?  Instead of selecting the Blocks and having it ferret out their insertion points, just Osnap to their insertion points directly:

 

(defun C:WHATEVER ()

  (command "_.pline" "_ins" pause "_ins" pause "")

)

 

No variables required, no sub-routines, etc.

 

Apart from your question, I have one:  Is there some reason not to draw just an ordinary Line?  A single-line-segment Polyline takes considerably more memory than a Line, so if you don't need to give it width, a Line is better.

Kent Cooper, AIA
Message 4 of 7

Sea-Haven
Mentor
Mentor

Two or more using same idea of pause.

 

(defun C:WHATEVER ( / oldsnap)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 64)
(princ "\nPick blocks C or Enter to stop")
(command "_pline" )
(while (= (getvar "cmdactive") 1 ) (command pause))
(setvar 'osmode oldsnap)
)
Message 5 of 7

atawk
Enthusiast
Enthusiast

thanks a lot it works fine for me. 

is there a possibility upgrade it so we can select more than two blocks at once? 

0 Likes
Message 6 of 7

Sea-Haven
Mentor
Mentor

Read my post again !!!

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@atawk wrote:

.... 

is there a possibility upgrade it so we can select more than two blocks at once? 


If by "select...at once" you mean by something like a window, rather than one at a time, then you would need to define some criteria by which a routine could determine the order  in which to connect their insertion points.

Kent Cooper, AIA
0 Likes