
(defun C:te (/ temp1 temp2 ent p1 ln11 ln12 dist1 dist2 p2 temp cen r ang1 ang2 n f k )
   (setvar "cmdecho" 0)
   (setq temp1 (entsel "\nSelect the object to be trimmed :"))
   (redraw (car temp1) 3)
   (setq temp2 (entget (car temp1)))
   (setq ent (cdr (assoc 0 temp2 )))
   (while (/= temp1 nil)
    (redraw (car temp1) 3)
    (setq temp2 (entget (car temp1)))
    (setq ent (cdr (assoc 0 temp2 )))

      (cond
       ( (= ent "LINE")
	(setq ln11 (cdr (assoc 10 temp2)))
	(setq ln12 (cdr (assoc 11 temp2)))
	(setq p1 (osnap (getpoint "\nSelect the point for trimming :") "int"))
	(setq dist1 (distance p1 ln11))
	(setq dist2 (distance p1 ln12))
	(if (> dist1 dist2)
	      (progn
	      (setq temp ln11)
	      (setq ln11 ln12)
	      (setq ln12 temp)
	      )
	)
	(setq n 1)
	(setq f (list p1))
	(redraw (car temp1 )1)
	(setq p1 (osnap (getpoint "\nSelect the point for trimming :") "int"))
	(while (/= p1 nil)
	 (setq f (append f (list p1)))	(setq n (+ n 1))
	 (setq p1 (getpoint "\nSelect the point for trimming :"))
	)
       (entdel (car temp1)) (setq n (- n 2)) (setq k 0)
       (command "line" ln11 (nth k f) "")
       (while (<= k n)
	(command "line" (nth k f) (nth (+ k 1) f) "")
	(setq k (+ k 1))
       )
       (command "line" (nth k f) ln12 "")
	)

       ((= ent "ARC")
	     (setq cen (cdr (assoc 10 temp2)))
	     (setq r (cdr (assoc 40 temp2)))
	     (setq ang1 (cdr (assoc 50 temp2)))
	     (setq ang2 (cdr (assoc 51 temp2)))
	     (setq ln11 (polar cen ang1 r))
	     (setq ln12 (polar cen ang2 r))
	     (setq p1 (osnap (getpoint "\nSelect the point for trimming :") "int"))
	     (setq dist1 (distance p1 ln11))
	     (setq dist2 (distance p1 ln12))
	     (setq n 1)
	     (setq f (list p1))
	     (redraw (car temp1 )1)
	     (setq p1 (osnap (getpoint "\nSelect the point for trimming :") "int"))
	     (while (/= p1 nil)
	      (setq f (append f (list p1)))  (setq n (+ n 1))
	      (setq p1 (getpoint "\nSelect the point for trimming :"))
	     )
	    (if (> dist1 dist2) (setq f (reverse f )))
	    (entdel (car temp1)) (setq n (- n 2)) (setq k 0)
	    (command "arc" "c" cen ln11 (nth k f))
	    (while (<= k n)
	     (command "arc" "c" cen (nth k f) (nth (+ k 1) f))
	     (setq k (+ k 1))
	    )
	    (command "arc" "c" cen (nth k f) ln12 )
       )

       ( (= ent "CIRCLE")
	    (setq cen (cdr (assoc 10 temp2)))
	    (setq p1 (osnap (getpoint "\nSelect the point for trimming :") "int"))
	    (setq n 1)
	    (setq f (list p1))
	    (setq ln12 p1)
	    (redraw (car temp1 )1)
	    (setq p1 (osnap (getpoint "\nSelect the point for trimming :") "int"))
	    (while (/= p1 nil)
	     (setq f (append f (list p1)))  (setq n (+ n 1))
	     (setq p1 (getpoint "\nSelect the point for trimming :"))
	    )
	   (entdel (car temp1)) (setq n (- n 2)) (setq k 0)
	   (while (<= k n)
	    (command "arc" "c" cen (nth k f) (nth (+ k 1) f))
	    (setq k (+ k 1))
	   )
	   (command "arc" "c" cen (nth k f) ln12 )
	)

       (T  (terpri) (princ (chr 7))
       (princ "********No entities be selected !!! (must be line, arc, circle) ") (terpri)
       )
      )
    (setq temp1 (entsel "\nSelect the object to be trimmed :"))
   )
    (setvar "cmdecho" 1)
)
