(defun C:double_trim (/ intersekt-points list-obj-1 list-obj-2 selekt-obj-1 selekt-obj-2 selekt-point-1 selekt-point-2)
  ; Режет два объекта на месте пересечения, пересечение ближайшее к выбору, обрезается выбраные части объектов.
  (geo_tools-help "double_trim")
  (load_global_variable)
  (setq list-obj-1 (entsel "\nВыбери первый объект: "))
  (cond
    ((eq list-obj-1 nil)
     (alert "Ничего не выбрано!"))
    ((not(or (eq (cdr(assoc 0 (entget (car list-obj-1)))) "LINE")(eq (cdr(assoc 0 (entget (car list-obj-1)))) "LWPOLYLINE")))
     (alert "Ошибка!\nВыбран не допустимый объект!\nВыбирать можно Отрезки и 2Dполилинии."))
    ((or (eq (cdr(assoc 0 (entget (car list-obj-1)))) "LINE")(eq (cdr(assoc 0 (entget (car list-obj-1)))) "LWPOLYLINE"))
     (setq list-obj-2 (entsel "\nВыбери второй объект: "))
     (cond
       ((eq list-obj-2 nil)
	(alert "Ничего не выбрано!"))
       ((not(or (eq (cdr(assoc 0 (entget (car list-obj-2)))) "LINE")(eq (cdr(assoc 0 (entget (car list-obj-2)))) "LWPOLYLINE")))
	(alert "Ошибка!\nВыбран не допустимый объект!\nВыбирать можно Отрезки и 2Dполилинии."))
       ((or (eq (cdr(assoc 0 (entget (car list-obj-2)))) "LINE")(eq (cdr(assoc 0 (entget (car list-obj-2)))) "LWPOLYLINE"))
	(setq selekt-obj-1 (vlax-ename->vla-object(car list-obj-1)))
	(setq selekt-obj-2 (vlax-ename->vla-object(car list-obj-2)))
	(if (equal selekt-obj-1 selekt-obj-2)
	  (alert "Ошибка!\nОдин и тот же объект выбран два раза!")
	  (progn
	    (setq intersekt-points (vlax-variant-value(vla-IntersectWith selekt-obj-1 selekt-obj-2 acExtendNone)))
	    (if (eq (vlax-safearray-get-u-bound intersekt-points 1)-1)
	      (alert "Ошибка!\nВыбранные объекты не пересекаются!")
	      (progn
		(setq intersekt-points(convert-safearray-to-list-points intersekt-points 3))
		(setq selekt-point-1(vlax-curve-getClosestPointTo selekt-obj-1(cadr list-obj-1)))
		(setq selekt-point-2(vlax-curve-getClosestPointTo selekt-obj-2(cadr list-obj-2)))
		(vla-StartUndoMark active_document)
		(if (> (length intersekt-points)1)
		  (progn
		    (edit-trim-obj selekt-obj-1 (analisis-intersekt-by-selekt selekt-obj-1 selekt-point-1 intersekt-points) selekt-point-1)
		    (edit-trim-obj selekt-obj-2 (analisis-intersekt-by-selekt selekt-obj-2 selekt-point-2 intersekt-points) selekt-point-2)
		    )
		  (progn
		    (edit-trim-obj selekt-obj-1 (car intersekt-points) selekt-point-1)
		    (edit-trim-obj selekt-obj-2 (car intersekt-points) selekt-point-2)
		    )
		  )
		(vla-EndUndoMark active_document)
		)
	      )
	    )
	  )
	)
       )
     )
    )
  (princ)
  )

(defun edit-trim-obj (vla-obj trim-point selekt-point / list-points n new-list-points vertex)
  ; "режет" линию или 2Dполилинию со стороны выбраной точки
  (cond
    ((eq (vla-get-ObjectName vla-obj) "AcDbLine")
     (if(<(vlax-curve-getDistAtPoint vla-obj selekt-point)(vlax-curve-getDistAtPoint vla-obj trim-point))
       (vla-put-StartPoint vla-obj (vlax-3D-point trim-point))
       (vla-put-EndPoint vla-obj (vlax-3D-point trim-point))
       )
     )
    ((eq (vla-get-ObjectName vla-obj) "AcDbPolyline")
     (setq list-points(convert-safearray-to-list-points(vlax-variant-value(vla-get-Coordinates vla-obj))2))
     (setq vertex(1+(fix(vlax-curve-getParamAtPoint vla-obj trim-point))))
     (if(<(vlax-curve-getDistAtPoint vla-obj selekt-point)(vlax-curve-getDistAtPoint vla-obj trim-point))
       (progn
	 (setq new-list-points (list trim-point))
	 (repeat (-(length list-points)vertex)
	   (setq new-list-points (append new-list-points(list (nth vertex list-points))))
	   (setq vertex(1+ vertex))
	   )
	 )
       (progn
	 (setq n 0)
	 (repeat vertex
	   (setq new-list-points (append new-list-points(list (nth n list-points))))
	   (setq n(1+ n))
	   )
	 (setq new-list-points (append new-list-points(list trim-point)))
	 )
       )
     (vla-put-Coordinates vla-obj (convert-list-points-to-lwpolyline-safearray new-list-points))
     )
    )
  (princ)
  )

(defun analisis-intersekt-by-selekt (selekt-obj selekt-point intersekt-points / distance-list selekt-distance vla-obj)
  ; выбирает близжайшее пересечение из списка относительно выбраной точки
  (setq selekt-distance(vlax-curve-getDistAtPoint selekt-obj selekt-point))
  (foreach x intersekt-points
    (setq distance-list(append distance-list(list(abs(- selekt-distance(vlax-curve-getDistAtPoint selekt-obj x))))))
    )
  (nth(analysis-number-item-in-list(apply 'min distance-list)distance-list)intersekt-points)
  )