Lisp to trim line

Lisp to trim line

smallƑish
Advocate Advocate
693 Views
3 Replies
Message 1 of 4

Lisp to trim line

smallƑish
Advocate
Advocate

is that possible to write a lisp?

1. draw a line, the user pick starting point

2. user picks the end of the line

3. Trim all crossing lines and polylines on the right-hand side of the user-defined line's direction.

Lisp to skip the steps; 

activating trim cmd, select the reference object as the drawn line by the user, and drag the mouse through the entire side of the line.

 

smallish_0-1692389644172.png

 

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

CodeDing
Advisor
Advisor
Accepted solution

@smallƑish ,

 

This should work for you, but PLEASE BE AWARE that if a line crosses the user-selected line by a Very Very Very small amount, this routine might not trim that line.

 

(defun c:CUT ( / *error* Line p1 p2 ang dist p3 p4 eLine)
  (defun *error* (msg)
    (if (not (member msg '("Function cancelled" "quit / exit abort")))
      (princ (strcat "\nError: " msg))
    )
    (if eLine (entdel eLine))
    (princ)
  )
  (defun Line (p1 p2)
    (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2)))
  )
  (initget 1)
  (setq p1 (getpoint "\nSelect First point of Cut: "))
  (initget 1)
  (setq p2 (getpoint p1 "\nSelect Second point of Cut: "))
  (setq ang (- (angle p1 p2) (* 0.5 pi)))
  (setq dist (* 0.0001 (getvar 'VIEWSIZE)))
  (setq p3 (polar p1 ang dist))
  (setq p4 (polar p2 ang dist))
  (setq eLine (Line p1 p2))
  (command "_.TRIM" eLine "" "_f" "_non" p3 "_non" p4 "" "")
  (entdel eLine)
);defun

 

0 Likes
Message 3 of 4

smallƑish
Advocate
Advocate

wow, it works like a blade in my drawings.

Thank you very much, This is what I was thinking. Loved it thank you very much

 

0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

No code needed look at the command 

(command "_.TRIM" eLine "" "_f" "_non" p3 "_non" p4 "" "")

 

Fence is a built in option to TRIM 

0 Likes