Closed polyline trim into another closed polyline

aitorm
Advocate
Advocate

Closed polyline trim into another closed polyline

aitorm
Advocate
Advocate

Imagine I have a closed polyline in autocad and then I create a line that cut the polygon in two vertex. I would love to have a lsp that ask me which side of the polygon to remove and subsitute the old polyline with the new cutted one.

 

aitorm_1-1728724734369.png

 

aitorm_2-1728724771102.png

 

 

But I don't know how to write lsp code, would you give me a hand?

 

Thank you

0 Likes
Reply
Accepted solutions (2)
584 Views
12 Replies
Replies (12)

hak_vz
Advisor
Advisor
Accepted solution

You can use command BOUNDARY. It does what you ask. 

Alternatively here is my code to avoid dialog and speed all up.

 

 

(defun c:clipClosedPoly (/ *error* pick e  pt pts)
	(defun *error* ()
		(setvar 'cmdecho 1)
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
      (princ)
    )
	(defun pick (msg)
		(setq e (car(entsel msg)))
		(if (and (not e) (= (getvar 'Errno) 7)) (pick msg) e)
	)
	(setq eo (vlax-ename->vla-object (pick  "\nSelect polyline >")) e nil)
	(if (/= (vlax-get eo  'ObjectName) "AcDbPolyline") (pick  "\nSelect polyline >"))
	(setq lo (vlax-ename->vla-object (pick  "\nSelect section line >")) e nil)
	(if (not (member(vlax-get lo  'ObjectName) '("AcDbLine" "AcDbPolyline"))) (pick  "\nSelect section line >"))
	(initget 1)
	(setq pt (getpoint "\nSelect point inside area to retain >"))
	(setvar 'cmdecho 0)
	(command "-boundary" pt "") 
	(setq pts (vlax-get (vlax-ename->vla-object (entlast)) 'coordinates))
	(vlax-put eo 'coordinates pts)
	(entdel (entlast))
	(vla-delete lo)
	(setvar 'cmdecho 1)
	(princ "\nDone!")
	(princ)
)

 

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Kent1Cooper
Consultant
Consultant

Can you just use BPOLY [or BOUNDARY] to make the side you want to keep?  Just a single pick in the side you want.  And ERASE the full-sized one.

Kent Cooper, AIA

calderg1000
Mentor
Mentor
Accepted solution

Regards @aitorm 

Try this code, it uses the standard method to do the clipping, and it gives you the option of closing the resulting polyline or leaving it open.

 

(defun c:nt( / s )
  (princ "\n Trim Objects Lwpolyline in Mode 'Standard'")
  (command "_trim" "o" "s" pause "" (setq s(entsel "\nSelect the side of the lwpolyline to crop...")) "")
  (Initget 1 "Y N")
  (setq opc(getkword"\nDo you want to close the clipped polyline...[Y/N]<Y>:"))
  (if (=  opc "Y")
  (entmod (subst(cons 70 129)(assoc 70 (entget(car s)))(entget(car s))))
          )
  (princ)
  )

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

aitorm
Advocate
Advocate

Thank you for your lisp!! It works like a charm!!!

 

 

0 Likes

aitorm
Advocate
Advocate
Thanks, but I need this command in a drawing with too many things, boundary would require many more steps (cleaning before and after).
0 Likes

aitorm
Advocate
Advocate

Loved it, favourite solution so far!! Just works very similar to trim command, and thats intuitive. Could be improved if it worked exactly as a trim command, for example, letting you choose several polylines and trim lines.

 

But more than marvellous enough with your lsp 🙂

 

Thanks

0 Likes

aitorm
Advocate
Advocate
I've got a little little bug. If you're cutting an arc in the polyline it will close the polyline with an arc 🙂
0 Likes

calderg1000
Mentor
Mentor

Regards @aitorm 

It should work fine with Lwpolylines with the following conditions, elevation=0 and closed. If the closure behaves like an arch. Previously apply Reverse to the lwpolyline...

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

omarsvn
Enthusiast
Enthusiast

is there a way to keep two polygons? I mean, keep the original polygon just divide for the lineScreenshot (112).png

0 Likes

hak_vz
Advisor
Advisor

@omarsvn  Try this! If you have only line segments than original polygon may be divided in n sub-polygons, and we can retain all his properties. If not than use this. It doesn't remove any original polygon or dividing line(s).

 

(defun c:boundaryByPickPoint (/ *error* p adoc)
	(defun *error* ()
		(setvar 'cmdecho 1)
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
      (princ)
    )
	(setq
		i 0
		adoc (vla-get-activedocument (vlax-get-acad-object)) 
	)
	(princ "\nPress <Enter> to exit loop!")
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	(while (setq p (getpoint (strcat " \nPick " (itoa (setq i (1+ i))) ". point >")))
		(command "._boundary" p "")
	)
	(vla-endundomark adoc)
	(princ "\nDone!")
	(princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes

omarsvn
Enthusiast
Enthusiast

It works good but I couldn't explain it to you really well, I dont want to keep the original polygon or the dividing line just the subpolygons, I dont know if possible separate the polygons by 0.135 when they have been divided

0 Likes

hak_vz
Advisor
Advisor

@omarsvn Try this.

Create polygon and separating lines. Run code, select separating lines and pick areas inside main polygon.

AT the and remove original polygon.

(defun c:boundaryByPickPoint (/ *error* p adoc i eo ss sm)
	(defun *error* ()
		(setvar 'cmdecho 1)
		(setvar 'osmode  old)
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
      (princ)
    )
	(setq
		i -1
		adoc (vla-get-activedocument (vlax-get-acad-object))
		old (getvar 'osmode)		
	)
	(princ "\nSelect dividing lines!")
	(setq ss (ssget '((0 . "*line"))) lst (entlast) sm (ssadd))
	(while (< (setq i (1+ i)) (sslength ss))
		(setq eo (vlax-ename->vla-object (ssname ss i)))
		(vla-offset eo 0.0675)
		(ssadd (entlast)sm )
		(vla-offset eo -0.0675)
		(ssadd(entlast) sm )
	)
	(princ "\nPress <Enter> to exit loop!")
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	(setvar 'cmdecho 0)
	(setvar 'osmode  0)
	(setq i 0)
	(while (setq p (getpoint (strcat " \nPick " (itoa (setq i (1+ i))) ". point >")))
		(command "._boundary" p "")
	)
	(setq i -1)
	(while (< (setq i (1+ i)) (sslength ss))
		(entdel (ssname ss i))
	)
	(setq i -1)
	(while (< (setq i (1+ i)) (sslength sm))
		(entdel (ssname sm i))
	)
	(setvar 'osmode  old)
	(setvar 'cmdecho 1)
	(vla-endundomark adoc)
	(princ "\nDone!")
	(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes