Polyline Break in same point problem

Polyline Break in same point problem

SAPER59
Advocate Advocate
676 Views
9 Replies
Message 1 of 10

Polyline Break in same point problem

SAPER59
Advocate
Advocate

I have a problem with a polyline that when breaking is same point, part of the polyline dissapears. Same happens if the commad is executed from command line.

Does anyone know how to solve the problem

I have a routin that breaks a closed polyline in 2 points using Break with first point option and selecting same point, and then do the same with the other point to eliminate the segment between them (as if it were a trim command) but with this polyline it doesn't works. When breaking it, instead of remain ony one polyline rimain 2 polylines without a criteria of what segment is created

Any help will be appreciated

Thanks

0 Likes
677 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

Your red outline is not a closed Polyline.  This part is separate from the rest:

Kent1Cooper_0-1722988004928.png

My guess is that the original was closed, you posted the drawing after having done what you describe instead of without doing it, and that the original start/end point was the upper left end of what's highlighted in my image.  In my experience, Breaking a closed Polyline at a single point has always resulted in two, with the original start/end vertex being the other ends of the two.

 

However, from your description, I wonder why you don't just use Break's First-point option and the two points you mention, "to eliminate the segment between them."  That's what it's for.  It's overkill to Break at single points in two locations if what you're going to do is take out the piece between.  Do I misunderstand?

Kent Cooper, AIA
0 Likes
Message 3 of 10

SAPER59
Advocate
Advocate

I used to do : select first and second oints  redefining them but some times what disappears is the other part, of the polyline, and I can not have  a criteria like if longest  or shortest part disappears is right or not 

Thanks anyway

0 Likes
Message 4 of 10

pendean
Community Legend
Community Legend

@SAPER59 wrote:

..but some times what disappears is the other part, of the polyline, ...


Yes it does: but with the BREAK command and NEA osnap running (nothing else) you can do this

pendean_0-1723060881935.png

 

 

The bring them back together with EXTEND command (crossing window)

pendean_1-1723060937454.png

 

 

breaking PLINEs are a pain, only workaround "work".

0 Likes
Message 5 of 10

komondormrex
Mentor
Mentor

@SAPER59,

check the following custom command for breaking a closed lwpolyline at any point.

 

;****************************************************************************************************

;	komondormrex, aug 2024

;	the custom command 'break_at_point' breaks a closed lwpolyline at any selected point on it.
;	when other than that entity is selected native command 'breakatpoint' used if applicable.

;****************************************************************************************************

(defun 2c_points (cnates_list / point_list)
  	(if cnates_list (setq point_list (cons (list (car cnates_list) (cadr cnates_list))
					       				   (2c_points (cddr cnates_list))
									 )
					)
	)
  	point_list
)

;****************************************************************************************************

(defun fix_decimal (decimal)
	(if (< (- (fix decimal) decimal -1.0) 1e-9)
		(1+ (fix decimal))
		(fix decimal)
	)
)

;****************************************************************************************************

(defun get_bulges (pline end_param / bulge_list index)
	(setq index -1)
	(repeat (1+ end_param)
		(setq bulge_list (append bulge_list (list (vla-getbulge pline (setq index (1+ index))))))
	)
)

;****************************************************************************************************

(defun set_bulges (pline bulge_list / index)
	(setq index -1)
	(foreach bulge bulge_list
		(vla-setbulge pline (setq index (1+ index)) bulge)
	)
)

;****************************************************************************************************

(defun split_list_nth (_list _nth)
  	(if (> _nth 0)
		(set 'split_before_nth (cons (car _list)
									 (split_list_nth (set 'split_after_nth (cdr _list)) (1- _nth))
							   )
		)
		(progn (set 'split_after_nth _list) (set 'split_before_nth nil))
	)
)

;****************************************************************************************************

(defun get_add_bulge (pline before_param vertex_add /
					  before_bulge vertex_add_segment_len before_vertex_add_len 1-4_inc_angle
					  1-4_add_before_inc_angle 1-4_add_after_inc_angle
					  before_vertex_add_bulge after_vertex_add_bulge
					 )
	(setq before_bulge (vla-getbulge pline before_param)
		  vertex_add_segment_len (- (vlax-curve-getdistatparam pline (1+ before_param))
			  						   (vlax-curve-getdistatparam pline before_param)
			  						)
		  before_vertex_add_len (- (vlax-curve-getdistatpoint pline vertex_add)
			  						  (vlax-curve-getdistatparam pline before_param)
			  					   )
	)
	(setq 1-4_inc_angle (atan (abs before_bulge))
		  1-4_add_before_inc_angle (* 1-4_inc_angle (/ before_vertex_add_len vertex_add_segment_len))
		  1-4_add_after_inc_angle (- 1-4_inc_angle 1-4_add_before_inc_angle)
		  before_vertex_add_bulge (* (/ before_bulge (abs before_bulge)) (tan 1-4_add_before_inc_angle))
		  after_vertex_add_bulge (* (/ before_bulge (abs before_bulge)) (tan 1-4_add_after_inc_angle))
	)
	(cons before_vertex_add_bulge after_vertex_add_bulge)
)

;****************************************************************************************************

(defun tan (rad_angle) (/ (sin rad_angle) (cos rad_angle)))

;****************************************************************************************************

(defun c:break_at_point (/ ename break_point end_param before_param pline vertex_list bulge_list
						   point_nth split_before_nth add_bulges
						)
	(setq ename (car (entsel "\nSelect object to break: ")))
	(if (and (= "LWPOLYLINE" (cdr (assoc 0 (entget ename))))
			 (not (zerop (getpropertyvalue ename "closed")))
		)
		(progn
			(setq break_point (mapcar '+ '(0 0)
							 	      (vlax-curve-getclosestpointto ename (getpoint "\nPick break point: "))
							  )
				  end_param (fix_decimal (1- (vlax-curve-getendparam ename)))
		  		  before_param (fix_decimal (vlax-curve-getparamatpoint ename break_point))
		  		  pline (vlax-ename->vla-object ename)
		  		  vertex_list (2c_points (vlax-get pline 'coordinates))
		  		  bulge_list (get_bulges pline end_param)
			)
			(cond
				((member break_point vertex_list)
					(setq point_nth (vl-position break_point vertex_list)
						  split_before_nth (split_list_nth vertex_list point_nth)
						  vertex_list (append split_after_nth split_before_nth (list (car split_after_nth)))
						  split_before_nth (split_list_nth bulge_list point_nth)
						  bulge_list (append split_after_nth split_before_nth (list (car split_after_nth)))
					)
					(vla-put-closed pline :vlax-false)
					(vlax-put pline 'coordinates (apply 'append vertex_list))
					(set_bulges pline bulge_list)
				)
				(t
					(if (zerop (vla-getbulge pline before_param))
						(setq add_bulges '(0 . 0))
						(setq add_bulges (get_add_bulge pline before_param break_point))
					)
					(setq
						  split_before_nth (split_list_nth vertex_list before_param)
						  vertex_list (append (list break_point) (cdr split_after_nth) split_before_nth
						  					  (list (car split_after_nth)) (list break_point)
									  )
						  split_before_nth (split_list_nth bulge_list before_param)
						  bulge_list (append (list (cdr add_bulges)) (cdr split_after_nth)
						  					 split_before_nth (list (car add_bulges)) '(0)
									 )
					)
					(vla-put-closed pline :vlax-false)
					(vlax-put pline 'coordinates (apply 'append vertex_list))
					(set_bulges pline bulge_list)
				)
			)
		)
		(progn
			 (princ "\nYou picked not closed pline, native command will be used - ")
			 (vl-cmdf "_breakatpoint" ename "\\")
		)
	)
	(princ)
)

;****************************************************************************************************

 

 

0 Likes
Message 6 of 10

hak_vz
Advisor
Advisor

I have been using this lisp for more than 20 years, one of the first functions that I wrote.

(defun c:bap ( / pt1 osnap_mode)
	(setvar 'cmdecho 0)
	(setq osnap_mode (getvar 'osmode))
	(setvar 'osmode 512)
	(while (setq pt1 (getpoint "\nPick breakpoint at polyline >"))
        (command "_.break" pt1 pt1))
	(setvar 'cmdecho 1)
	(setvar 'osmode osnap_mode)
	(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
Message 7 of 10

SAPER59
Advocate
Advocate

Thanks komodormrex, but if you have a look in the PLINE I upload (that must be joined because I update after breaking) if I run the commads you sent me, they don't break it.

Anyway I will test it further, but I will have to continue as I did nnow, that instead of breaking it in one step, work around and control objects created after break command and remake the polyline, more complicated, but works

0 Likes
Message 8 of 10

komondormrex
Mentor
Mentor

it breaks a closed pline at a point.

komondormrex_1-1723638035604.gif

similarly if point is already there

komondormrex_1-1723638878106.gif

 

as opposed to native command

komondormrex_0-1723638427579.gif

 

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant

@hak_vz wrote:

I have been using this lisp for more than 20 years.....


When used on a closed Polyline, that has the same problem as described in Message 1:  "When breaking it, instead of remain ony one polyline rimain 2 polylines."  I believe @SAPER59  wants it to be one Polyline that now starts and ends at the place they picked, but is not "closed" in the official sense.

Kent Cooper, AIA
0 Likes
Message 10 of 10

john.uhden
Mentor
Mentor

@Kent1Cooper ,

Been there, done that an excruciating number of times this past Spring.

You just can't break a closed polyline or circle at one point.

Whereas if you create a tiny circle at the desired break point you can trim inside the circle (gotta zoom in before trimming).

Now that leaves a gap, but so small that you can't see it in a plot.

John F. Uhden

0 Likes