special polyline break only at the picked point

special polyline break only at the picked point

GeryKnee
Advocate Advocate
3,954 Views
17 Replies
Message 1 of 18

special polyline break only at the picked point

GeryKnee
Advocate
Advocate

A code like the following sould be usefull.

A lisp code , starts execution asking for an intemidiate polyline point  (a point between two vertices).

After the Point defined, polyline breaks only in that part (between the two vertices).

  So , after execution there will be one line (the broken section of polyline) and perhaps one (if polyline where closed ) or two (if was not closed) remaining parts of the "broken poly". If there will be two parts , then , both of them will retain their previous direction.

Thanks,

Gery.

 

0 Likes
Accepted solutions (1)
3,955 Views
17 Replies
Replies (17)
Message 2 of 18

Moshe-A
Mentor
Mentor

Dear @GeryKnee ,

 

Before i'll start coding this please explore AutoCAD BREAK command and tell us what do you think?

 

Moshe

0 Likes
Message 3 of 18

Moshe-A
Mentor
Mentor

especially this?

 

Although it says it does not break a closed objects, it does works on a closed pline by first open it.

 

Moshe-A_1-1616234977011.png

 

0 Likes
Message 4 of 18

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

...n asking for an intemidiate polyline point  (a point between two vertices).  After the Point defined, polyline breaks only in that part (between the two vertices). ....


If by that you mean you want the Polyline broken from vertex to vertex, that is, you want the entire segment on which you picked to be broken out, you can use TRIM and pick the Polyline as the trimming boundary, and then any segment you pick on will be trimmed away / broken out.

Kent Cooper, AIA
0 Likes
Message 5 of 18

GeryKnee
Advocate
Advocate

Hello Mosh,

Thank you for your interest.

The break function  of autocad : 1)  asks for polyline object 2) asks for for a point (vertex of the polyline) to break. After the break, the user doesn't know in wich direction the break will occure (clockwise or anticlock wise left or right of the defined polyline vertex ) because that depends on the polyline's direction. I speak about just 1 user's action (one point) that ::: 1st) defines the polyline under this point and 2nd) defines the line part of polyline that will be broken and deleted.

Thanks,

Regards,

Gery.

0 Likes
Message 6 of 18

ВeekeeCZ
Consultant
Consultant

Here's my routine.... at some moment I thought it would be useful... time has shown that no so much.

 

ANYWAY - you (using old acad) might have issues with the correct syntax of the BREAK command. Let's see...

0 Likes
Message 7 of 18

GeryKnee
Advocate
Advocate

I speak just for polylines break.

an example

J0 - Copy (3).jpg

 a 2nd example

 

J0 - Copy (4).jpg

0 Likes
Message 8 of 18

ВeekeeCZ
Consultant
Consultant

If your goal is actually to remove the segment, select the segment with the CTRL key pressed, hit the DEL button.

0 Likes
Message 9 of 18

GeryKnee
Advocate
Advocate

hello Kent,

Yes , i speak about what trim does in case of an open polyline in wich vertex 0 has different coordinates to last polyline vertex. But that needs after call three user actions (left mouse clik, right mouse clik, and left mouse clik to the same position) , while one left mouse click is enough.

0 Likes
Message 10 of 18

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

I speak just for polylines break.

an example.... 


You don't say whether the original Polyline in the first example is closed in AutoCAD's meaning of the word, or just goes back to the start point without technically being closed.  If it's closed, I think [not on an AutoCAD computer right now to check] TRIM will do exactly what you show, without affecting the drawn direction(s).  If it's not closed, the result in first example would be two Polylines that touch at the original start-end.

Kent Cooper, AIA
0 Likes
Message 11 of 18

Kent1Cooper
Consultant
Consultant
Accepted solution

@GeryKnee wrote:

... trim ... needs after call three user actions (left mouse clik, right mouse clik, and left mouse clik to the same position) , while one left mouse click is enough.


If there are no other objects crossing the segment to be removed, it can be done by typing TR {Enter/space twice, once to register the command alias and once to use everything as Trim boundaries}, one pick on the segment to be removed, {Enter/space} to conclude.

 

But [again, I'm not on a computer to test it with] if you want a one-click command, can it be as simple as this?

 

(defun C:BPSO (/ pt); = Break Polyline Segment Out
  (setq pt (getpoint "\nPick on Polyline Segment to Break Out: "))
  (command "_.trim" pt "" pt "")
  (princ)
)

 

 

Kent Cooper, AIA
Message 12 of 18

GeryKnee
Advocate
Advocate

OK Kent,

That's almost perfect.

Thank you very much,

regards,

Gery.

0 Likes
Message 13 of 18

hak_vz
Advisor
Advisor

I hope I'm not to late. Try this

 

(defun c:remove_segment ( / *error* i lwpoly_segments old p1 p2 p3 ss e eo dist_1 dist_2 dist_3 done seg seglst);
	(defun *error* ( msg )
		(princ "error: ")
		(princ msg)
		(setvar 'osmode old)
		(princ)
	)
	(defun lwpoly_segments ( e / ent p1 pt bulge seg seglst)
	(setq ent (entget e))
	(cond (ent
		 (if (= (logand (cdr (assoc 70 ent)) 1) 1)
		   (setq p1 (cdr (assoc 10 ent)))
		 )
		 (while (setq ent (member (assoc 10 ent) ent))  
		   (setq seg   nil)
		   (if (and pt bulge)
			 (setq seg (list pt bulge))
		   )
		   (setq pt    (cdr (assoc 10 ent))
				 ent (member (assoc 42 ent) ent)
				 bulge (cdar ent)
				 
		   )
		   (if seg
			 (setq seg (list (car seg)(cadr seg)pt);(append seg (list pt))
				   seglst (cons seg seglst))
		   )
		 )
		)
  )
  (if p1 (setq seglst (cons (list pt bulge p1) seglst)))
  (reverse seglst)
)
	(setq old (getvar 'osmode)) 
	(setvar 'osmode 512)
	(setq p3 (getpoint "\nSelect point at removing segment: "))
	(cond
		((and p3)
		 
			(setq p1(mapcar '+ p3 '(1 1)) p2(mapcar '- p3 '(1 1)))
			(setq ss (ssget "_C"  p1 p2 '((0 . "LWPOLYLINE"))))
			(setq e(ssname ss 0) eo (vlax-ename->vla-object e))
			(setq p3 (vlax-curve-getClosestPointTo eo p3))
			(setq dist_2 (vlax-curve-getDistAtPoint eo p3))
			(setq seglst (lwpoly_segments e))
			(setq i -1)
			(while (and (< (setq i (1+ i)) (length seglst)) (not done))
				(setq seg (nth i seglst))
				(setq dist_1(vlax-curve-getDistAtPoint eo (car seg)) dist_3(vlax-curve-getDistAtPoint eo (last seg)))
				(cond
					((and (> dist_2 dist_1)(< dist_2 dist_3))
						(setvar 'cmdecho 0)
						(command "_.break" (car seg) (car seg) )
						(command "_.break" (last seg) (last seg))
						(setq ss (ssget "_C"  p1 p2 '((0 . "LWPOLYLINE"))))
						(command "_.erase" ss "") 
						(setq done T)
						(setvar 'cmdecho 1)
					)
				)
			)
		)
	)
	(setvar 'osmode old)
	(princ "\nDone!")
	(princ)
)
(princ "\nCommand REMOVE_SEGMENT removes segment from lwpolyline!")
(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 14 of 18

Sea-Haven
Mentor
Mentor

Is the perfect answer to do with clockwise v's anticlockwise pline can be done, when asked for pt can use that with ssget pt and then get entity name, when you break the pline you can use entlast to get the new entity name, so can reverse the plines if required.

0 Likes
Message 15 of 18

stevor
Collaborator
Collaborator

Guessing from your diagram, but not your dialog, that you are

concerned about the sequence number of each vertex.

The database does not use such a feature, it uses the sequence.

If you need to keep track of a vertex, you could store it coordinates.

Or for all of them, you could create another object, or entity, at each vertex.

S
0 Likes
Message 16 of 18

Sea-Haven
Mentor
Mentor

Checking clockwise or anti for plines can have answer that matches the vertice order. Use pedit reverse.

0 Likes
Message 17 of 18

GeryKnee
Advocate
Advocate

Hello sir,

Of course, if not polyline is "closed" after the code excuted there will be two plyline variants.

But if polyline was "closed" or coordinates of the first vertex ehere the same as the last , there nust be created one polyline.

This is described at my second example.

Anyway, the suggested codes of the community do the 90% of what i need.

Thank you very much,

Gery.

 

0 Likes
Message 18 of 18

Anonymous
Not applicable

Hmm I upgraded to 2021 version not so long ago.  Before that I ha a button in my toolbar that did:  

^C^Cbreak \_f \ @

 

You could break a self intersecting polyline at any crossing. Now it seems the break command seems changed. That butten does something completely different.

0 Likes