Please Help to give me a lisp code to connect all selected blocks basepoint connected with right angled polylines.

Please Help to give me a lisp code to connect all selected blocks basepoint connected with right angled polylines.

ritzofriya
Advocate Advocate
1,053 Views
11 Replies
Message 1 of 12

Please Help to give me a lisp code to connect all selected blocks basepoint connected with right angled polylines.

ritzofriya
Advocate
Advocate

Please Help to give me a lisp code to connect all selected blocks basepoint connected with right angled polylines.

0 Likes
Accepted solutions (2)
1,054 Views
11 Replies
Replies (11)
Message 2 of 12

Valentin_CAD
Mentor
Mentor

@ritzofriya ,

 

Welcome to the AutoCAD Community Forum.

 

Apart from this forum, there is also a Visual LISP, AutoLISP and General Customization.



Select the "Mark as Solution" if my post solves your issue or answers your question.

Seleccione "Marcar como solución" si mi publicación resuelve o responde a su pregunta.


Emilio Valentin

0 Likes
Message 3 of 12

Kent1Cooper
Consultant
Consultant

... and when you go to the Customization Forum, give more detail.  A sample drawing or image may help, but it may not answer the first question that comes to my mind:  what criteria should be used to determine which of the two possible right-angled Polyline routes that can connect any two locations should be used?  That is, in this image, red or yellow?

Kent1Cooper_0-1628017848241.png

Second question:  Am I correct to assume you mean orthogonal-only right-angled Polylines?  If not necessarily, more criteria would be needed, since there are an infinite number of possible routes.

Kent1Cooper_1-1628018141100.png

 

 

Kent Cooper, AIA
Message 4 of 12

ritzofriya
Advocate
Advocate

Capture.JPG

 an example here (your  option 2 is perfect for me )

0 Likes
Message 5 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

This seems to do that, in limited testing:

 

(defun C:LBRAP ; = Link Blocks with Right-Angle Polylines
  (/ ss inspts RtoL n)
  (prompt "\nTo Link Blocks with Right-Angle Polylines,")
  (if (setq ss (ssget '((0 . "INSERT"))))
    (progn ; then
      (setq
        inspts (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
        RtoL (vl-sort inspts '(lambda (a b) (> (car a) (car b))))
      ); setq
      (repeat (setq n (1- (length RtoL)))
        (command "_.pline"
          "_non" (nth n RtoL)
          "_non" (list (car (nth (1- n) RtoL)) (cadr (nth n RtoL)))
          "_non" (nth (setq n (1- n)) RtoL)
          ""
        ); command
      ); repeat
    ); progn
  ); if
  (princ)
); defun

 

It could be enhanced to put the Polylines on a specific Layer, and/or to ensure that PLINEWID is set to what you want, and/or to have Undo begin/end wrapping, etc., etc.

 

Be aware that if any Blocks are vertically aligned [i.e. at the same X coordinate], you may want a result like this:

Kent1Cooper_1-1628522542460.png

[I colored two of the Polyline links for comparison], in which there is no overlap.  But you could get a result like this instead:

Kent1Cooper_0-1628522420292.png

in which the yellow link goes up to the uppermost Block, and the red one comes down from there, overlapping the yellow.  Which way it does it depends on the drawn order of the Blocks.  Whether that can be controlled, I'm not sure.

Kent Cooper, AIA
Message 6 of 12

Sea-Haven
Mentor
Mentor

Hi Kent, when drawing a line etc you can use the .X .Y is this maybe the method that is required check the x1=x2 or y1=y2 etc. Still a complex if and but. It may all fall apart depending on the pattern of blocks.

0 Likes
Message 7 of 12

ritzofriya
Advocate
Advocate

Thank you so much you made the real solution. thanks a loooot 

0 Likes
Message 8 of 12

ritzofriya
Advocate
Advocate
This program is really amazing.. loved it too.. if it can avoid overlapping it will be great.. crossing can be better than overlap. anyway thanks a lot,,,
0 Likes
Message 9 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

@ritzofriya wrote:
.... if it can avoid overlapping it will be great.. crossing can be better than overlap. ....

Thinking about that, I realize that if one of those that are vertically aligned is higher than the one to the left from which the link is coming, and the other one is lower, there is no way to avoid overlap when the link routes start horizontally.  Again, depending on the drawn order between the vertically-aligned ones, you get one of these:

Kent1Cooper_0-1628595674920.png

[I made the red one broken so you can see what the yellow one does behind it.]

 

I assume the "ideal" solution would be to have that yellow link start vertically, like this:

Kent1Cooper_1-1628595859973.png

but how to get the routine to recognize the situation and do it that way will be a challenge to work out.

 

And if there might ever be more than two that align vertically....

 

Can you post an image or small drawing of what you imagine the links doing in a "crossing" situation?

 

Kent Cooper, AIA
0 Likes
Message 10 of 12

ritzofriya
Advocate
Advocate

Capture.JPG

 The yellow case you program working great.. but in red its difficult, it should work like blue, that's what I m dreaming...

0 Likes
Message 11 of 12

Kent1Cooper
Consultant
Consultant

@ritzofriya wrote:

.... it should work like blue, that's what I m dreaming...


That may not be possible in a single command.  It would need some way of deciding which Block to start with, and which to go to next.  My earlier routine does that by sorting them by their horizontal positions [the X coordinate of their insertion points], which of course gives you the results outlined in yellow and red.  Another possible way would be to go to the nearest other Block, but if your arrangement outlined in blue started at the upper left, the nearest other Block would be the one below it, not the one to the right.

 

Unless some unambiguous criteria can be developed for determining the sequence, in your blue outline you could do the top row in one command, the bottom row in another, and the right end in another.

 

Determining the sequence would be a real challenge for a routine, but your eyes and brain can do it very easily and instantaneously.  If you're willing to pick the Blocks one by one in the sequence you want, it would be easy to make a routine that would put 90°-bend links in as you go.

Kent Cooper, AIA
0 Likes
Message 12 of 12

ritzofriya
Advocate
Advocate

if i can provide a reference polyline. with reference to that it can do the function ?

0 Likes