Break both ends of the selected polylines at a given distance with Lisp program

Break both ends of the selected polylines at a given distance with Lisp program

eakos1
Advocate Advocate
657 Views
2 Replies
Message 1 of 3

Break both ends of the selected polylines at a given distance with Lisp program

eakos1
Advocate
Advocate

I need a LISP program which can break both ends of the selected lines at. 15mm distance and put them into another layer. 

 

I've created an LISP program and it is working.  But sometimes at certain polylines the break is not in one ponint but a small distance is missing if more polyline is selected at once. However if I select these polylines but only one  and let the program run  one by one the break is in one point in each polyline. What can be the problem, has someone any idea?

 

 

eakos1_0-1619732897716.png     

 

If I click on the same lines on by one the result is great.

eakos1_1-1619733030045.png

 

(defun C:BRAKE_15 (/ selection name data end15 start15 counter lastCreatedObject listOfCreatedObjects)

 

(vl-load-com)

(setq selection (ssget)) ;(list (cons 0 "LWPOLYLIN"))))
(setq numberOfSelected (sslength selection))
(setq counter 0)

 

(repeat numberOfSelected
  (setq name (ssname selection counter))
  (setq data (entget name))
  (setq end15 (vlax-curve-getPointAtDist name (- (vlax-curve-getDistAtPoint name (vlax-curve-getEndPoint name) ) 15 ) ) 

)

 

(COMMAND "BREAK" name end15 end15)
(setq lastCreatedObject (entlast))
(command "chprop" lastCreatedObject "" "Layer" "text" "layer" "1_mm_none" "color" "bylayer" "")

 

(setq start15 (vlax-curve-getPointAtDist name 15))

(COMMAND "BREAK" name start15 start15)
(setq lastCreatedObject (entlast))


(setq counter (+ 1 counter))

) ;end repeat
----------------------------------------------------------------------------------------
;here we change the layer of the selected polylines because after breack of the start 15mm line it get the name of the original polyline
(setq counter 0)
(repeat numberOfSelected
(setq name (ssname selection counter))
(setq data (entget name))
(command "chprop" name "" "Layer" "text" "layer" "1_mm_none" "color" "bylayer" "")
(setq counter (1+ counter))
) ;end repeat

 

(princ)
) ;end defun

 

    

0 Likes
Accepted solutions (1)
658 Views
2 Replies
Replies (2)
Message 2 of 3

CodeDing
Advisor
Advisor
Accepted solution

@eakos1 ,

 

Try turning off your OSNAPs and see if that does it for you:

(defun C:BRAKE_15 ( / osm selection name data end15 start15 counter lastCreatedObject listOfCreatedObjects)
(vl-load-com)
(setq osm (getvar 'OSMODE))
(setvar 'OSMODE (logior 16384 osm))
.....
.....
.....
(setvar 'OSMODE osm)
(princ)
) ;end defun

Best,

~DD

Message 3 of 3

eakos1
Advocate
Advocate

Thank you, now the program works fine. 😀

 

But I had to rewrite/extend because the 2D polylines behaves differently. 

LWPOLYLINE - after breake the longest part keeps its name

2D POLYLINE - after breake both lines get a new name - aaahhhh 😙

0 Likes