LISP TO CONNECT POLYLINES AUTOMATICALLY

LISP TO CONNECT POLYLINES AUTOMATICALLY

borijarim
Participant Participant
2,934 Views
13 Replies
Message 1 of 14

LISP TO CONNECT POLYLINES AUTOMATICALLY

borijarim
Participant
Participant

Hello, I have two polylines in the same layer as such 

borijarim_0-1680095224976.png

 

I want a lisp that will detect this and automatically connect them with a line of the same layer 

borijarim_1-1680095399529.png

 

Note that i will have multiple polylines to connect and different layers.

 

I have attached my test file, thank you 🙂

0 Likes
2,935 Views
13 Replies
Replies (13)
Message 2 of 14

Automohan
Advocate
Advocate

Note: Join all in a selection:

Try this !

 

(defun c:pj ( / pe ss )
 (setq pe (getvar 'PEDITACCEPT))
 (setvar 'PEDITACCEPT 1)
 (if (and (setq ss (ssget "_:L" '((0 . "ARC,LINE,LWPOLYLINE"))))
          (setq fuzz (getdist "\nFuzz distance <0>: ")))
   (command "_.pedit" "_M" ss "" "_J" "Jointype" "_A" fuzz "")
 (setvar 'PEDITACCEPT pe)
(princ))

Slightly modified

 

 

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 3 of 14

Shneuph
Collaborator
Collaborator

I see this forum is a place for peers to help each other solve problems and teach one another how to program in AutoLISP and customize AutoCAD; not a form for people to fill out, placing an order for free software that will make doing their job easier.

 

If you posted some sort of sample code that you had written and need help with, there are many generous people who graciously spend their time and lend their expertise to help others.  I have received a whole lot of invaluable help from others here that I am very grateful for.

 

However, why anyone would spend time replying to these "I want a LISP..." posts, when the op has not given any indication of attempting to solve themselves, is beyond me.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 14

Automohan
Advocate
Advocate

Another one:

(defun c:jf () (c:pljoinfuzz)) ; this line can be commented out if there is an existing command called jf
(defun c:pljoinfuzz (/ ss1 entLine objType oldcmdecho oldpeditaccept fuzz okObjects)
  (setq oldcmdecho (getvar "cmdecho"))
  (setq oldpeditaccept (getvar "PEDITACCEPT"))
  (setvar "cmdecho" 0)
  (setq A2k4 (>= (substr (getvar "ACADVER") 1 2) "16"))
  (if A2k4 (setvar "PEDITACCEPT" 0))
  (setq	okObjects '((0 . "LINE,ARC,POLYLINE,LWPOLYLINE")))
  (princ "\nSelect object to join: ")
  (setq ss1 (ssget okObjects))
  (setq fuzz (getdist "\nFuzz distance <0>: "))
  (if (= fuzz nil) (setq fuzz 0))
  (if (/= ss1 nil)
      (progn
	(setq objType (cdr (assoc 0 (entget (setq entLine (ssname ss1 0 ))))))
	(if (= (sslength ss1) 1) (setq ss1 (ssget "X" okObjects)))
	(if (member objType '("LINE" "ARC"))
	  (command "_.pedit" "_M" ss1 "" "_Y" "_J" "_J" "_B" fuzz "")
	  (command "_.pedit" "_M" ss1 "" "_J" "_J" "_B" fuzz ""))))
  (setq ss1 nil)
  (setvar "cmdecho" oldcmdecho)
  (if A2k4 (setvar "PEDITACCEPT" oldpeditaccept))
  (princ))
"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
Message 5 of 14

borijarim
Participant
Participant

I asked that question thinking that there might be someone who already had a lisp for this on hand. That's because I've already seen in posts in this forum similar to this and where people explained their problem and others actually posted the lisps they had found before or made. I don't see the problem. If you don't want to do that then just ignore i guess.

Therefore i dont see why you would answer like that, just skip the post if you dislike it so much.

0 Likes
Message 6 of 14

borijarim
Participant
Participant

Thank you for replying 😄 

I'll be trying it 🙂

0 Likes
Message 7 of 14

borijarim
Participant
Participant

Thanks so much 😄

I'll get back at you as soon as i try it ;D

0 Likes
Message 8 of 14

Kent1Cooper
Consultant
Consultant

@borijarim wrote:

.... I have two polylines .... detect this and automatically connect them with a line .... 


I don't see anything in the offerings so far to make the Line [green in your image] to connect the Polylines.  Am I correct that the connecting Line does not yet exist, and needs to be drawn as part of the process?

EDIT:  Maybe  PEDIT / Multiple / [selection] / Join / big-fuzz-factor  can serve your purpose.  Here:

Kent1Cooper_0-1680107595140.png

starting with the top situation, it does not do the middle [green line connecting as in your example], but rather does the bottom [Filleting the closer end segments of the originals].  But no code is required, and it can do multiples at once [depending on the specific geometries].

Kent1Cooper_1-1680108588442.png

Does that work for you?

Further EDIT:  You speak of multiple such situations, and want a routine to "detect this" [the gap to be filled/joined].  Post an image or sample drawing with realistic conditions.  If there are multiples, by what criteria could a routine determine which ones constitute pairs that should be joined?  Might a given Polyline be closer in some direction to one it should not be joined to than to the one it should be joined to?  Etc.

Kent Cooper, AIA
Message 9 of 14

3wood
Advisor
Advisor

I just amend Kent's solution with 2 more steps.

PEDIT / Multiple / [selection] / Join / Jointype / Add / big-fuzz-factor

0 Likes
Message 10 of 14

borijarim
Participant
Participant

hi can't really find that big buzz factor? Can it do multiple lines at once? 

0 Likes
Message 11 of 14

borijarim
Participant
Participant

Hello, thank you so much for your reponse. 

Indeed i would like a routine that can find (detect) them and correct them. Usually when i edit them manually, i look for polylines that are within the same layer, and are closer together than they are closer to anything else.

Also for the routine that you gave me, (i cant really find the big buzz factor), can it do multiple polylines at once? or do i have to select every couple alone?

0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

Yes, it can do multiples -- see the second image in Message 8, where all of those pairs on the left were turned into all the joined ones on the right, in one PEDIT command.

 

You don't "find" the big fuzz factor.  It asks you for one.  Give it a big enough number to exceed the likely size of the gaps you want to close.

Kent Cooper, AIA
0 Likes
Message 13 of 14

borijarim
Participant
Participant

Take these for example

borijarim_0-1682601601348.png

the result is the following

borijarim_1-1682601623140.png

what can i do 

0 Likes
Message 14 of 14

Kent1Cooper
Consultant
Consultant

That looks like you used a bigger fuzz factor than you need, but you don't show what you want as a result instead.  Even if you want that big a fuzz factor, if you don't want the sharp point at the right, use PEDIT/Multiple/[select]/Join/Jointype and change that to the Add rather than the Extend mode.

Kent Cooper, AIA
0 Likes