Jump to content

Need Lisp To Extend Polylines To The First Intersection


Engineer_Yasser

Recommended Posts

 

Please I Need Lisp To Extend Selected Polylines To The First Intersection Only

When I Select All Yellow Polylines, Extend Till Intersect With The 1st Yellow Polyline Then Stop

 

1.png.271c6b77d9b6aaf19592111a880e939b.png

 

 

 

2.thumb.png.f9bc69ec777b994a53d0d121099f1264.png

Sample.dwg

Link to comment
Share on other sites

 

I succeeded in creating Lisp 90% Perfect  ...

Can anyone optimize it for not looping all the polylines but only polylines within 50m from the polyline start point.

I used ( Intersections  -  Lee Mac ) function

 

(if (setq ss (ssget '((0 . "LWPOLYLINE"))))
    (progn
		(vl-cmdf "change" "p" "" "p" "TH" 0 "")
		(vl-cmdf "change" "p" "" "p" "EL" 0 "")
		(repeat (sslength ss)
			(setq pline_ent (ssname ss 0))
			(setq pline_entget (entget pline_ent))
			(setq pline_obj (vlax-ename->vla-object pline_ent))
			(setq pline_Start (list (car (vlax-curve-getStartPoint pline_obj)) (cadr (vlax-curve-getStartPoint pline_obj))))
			(setq pline_End (list (car (vlax-curve-getEndPoint pline_obj)) (cadr (vlax-curve-getEndPoint pline_obj))))
			
			(setq min_dist 9999999999)
			(setq nPoint '())
			(setq n 1)
			(repeat (1- (sslength ss))
				(setq X_ent (ssname ss n))
				(setq X_pline (entget X_ent))
				(setq X_ent_Obj (vlax-ename->vla-object X_ent))
				(if (setq X_point_list (LM:intersections pline_obj X_ent_Obj acExtendThisEntity))
					(progn
						(setq nPoint (list (car (car X_point_list)) (cadr (car X_point_list))))
						(setq dist1 (distance nPoint pline_Start))
						(setq dist2 (distance nPoint pline_End))
						(if (< dist1 dist2)
							(if (and (< dist1 min_dist) (< dist1 50))
								(progn
									(setq min_dist dist1)
									(setq final_start pline_Start)
									(setq final_nPoint nPoint)
								)
							)
						)
						
					)
				)
				(setq n (1+ n))
			)
				
			(setq x 0)
			(repeat (length pline_entget)
				(if (and (= (car (nth x pline_entget)) 10) (equal final_start (cdr (nth x pline_entget)))) (entmod (setq pline_entget (subst (cons 10 final_nPoint) (nth x pline_entget) pline_entget))))
				(setq x (1+ x))
			)
			
			(setq min_dist 9999999999)
			(setq nPoint '())
			(setq n 1)
			(repeat (1- (sslength ss))
				(setq X_ent (ssname ss n))
				(setq X_pline (entget X_ent))
				(setq X_ent_Obj (vlax-ename->vla-object X_ent))
				(if (setq X_point_list (LM:intersections pline_obj X_ent_Obj acExtendThisEntity))
					(progn
					  	(if (car (cdr X_point_list))
						  	(setq nPoint (list (car (car (cdr X_point_list))) (cadr (car (cdr X_point_list)))))
							(setq nPoint (list (car (car X_point_list)) (cadr (car X_point_list))))
						)
						(setq dist1 (distance nPoint pline_Start))
						(setq dist2 (distance nPoint pline_End))
						(if (< dist2 dist1)
							(if (and (< dist2 min_dist) (< dist2 50))
								(progn
									(setq min_dist dist2)
									(setq final_End pline_End)
									(setq final_nPoint nPoint)
								)
							)
						)
						
					)
				)
				(setq n (1+ n))
			)
				
			(setq x 0)
			(repeat (length pline_entget)
				(if (and (= (car (nth x pline_entget)) 10) (equal final_End (cdr (nth x pline_entget)))) (entmod (setq pline_entget (subst (cons 10 final_nPoint) (nth x pline_entget) pline_entget))))
				(setq x (1+ x))
			)
			(ssdel pline_ent ss)
			(ssadd pline_ent ss)
		)
		(vl-cmdf "regen")
	)
)
			
        
(defun LM:intersections ( ob1 ob2 mod / lst rtn )
    (if (and (vlax-method-applicable-p ob1 'intersectwith)
             (vlax-method-applicable-p ob2 'intersectwith)
             (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
        )
        (repeat (/ (length lst) 3)
            (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
                  lst (cdddr lst)
            )
        )
    )
    (reverse rtn)
)

 

Edited by Engineer_Yasser
Link to comment
Share on other sites

This was something that I also challenged myself to do. Though not perfect, the purpose of this program was to "neaten" Revit exported or similar pipelines so that they are all "filleted" and "trimmed" cleanly so that it works with my other commands that I've created.

 

I don't know how useful this will be, but if it doesn't suit your requirements, I'll give another crack at it.

 

You will probably just have to select the lines separately (the yellow and green lines).

image.png.8268c330dc20aaa5e2a500c941019da3.png

 

image.png.b99562a6b74a0772fd5a31c31578b282.png

 

 

Neaten.lsp

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, Jonathan Handojo said:

This was something that I also challenged myself to do. Though not perfect, the purpose of this program was to "neaten" Revit exported or similar pipelines so that they are all "filleted" and "trimmed" cleanly so that it works with my other commands that I've created.

 

I don't know how useful this will be, but if it doesn't suit your requirements, I'll give another crack at it.

 

You will probably just have to select the lines separately (the yellow and green lines).

image.png.8268c330dc20aaa5e2a500c941019da3.png

 

image.png.b99562a6b74a0772fd5a31c31578b282.png

 

 

Neaten.lsp 14.62 kB · 1 download

 

@Jonathan Handojo

 

I don't know how to thank 😍 you for your help, The lisp is working very fast and Perfect 💯 🌹🌹

 

Thanks Again ❤️

 

Link to comment
Share on other sites

17 hours ago, Engineer_Yasser said:

 

@Jonathan Handojo

 

I don't know how to thank 😍 you for your help, The lisp is working very fast and Perfect 💯 🌹🌹

 

Thanks Again ❤️

 

No worries. Glad it worked.

 

While you're at it, try this one, to remove all those annoying vertices. It's quite satisfying to see it

RXV.lsp

  • Thanks 1
Link to comment
Share on other sites

11 hours ago, Jonathan Handojo said:

No worries. Glad it worked.

 

While you're at it, try this one, to remove all those annoying vertices. It's quite satisfying to see it

RXV.lsp 14.28 kB · 1 download

 

I appreciate your help .. This lisp makes the drawing much better  😍🌹

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...