(defun C:insert-image-by-coordinate (/ patch-img patch-dat bl-p1 bl-p2 bl-p3 bl-p4 dialog-var list-dat obj xy-p1 xy-p2 xy-p3 xy-p4)
  ; Вставка изображений из SAS.планета с привязками в файле .dat
  (setq patch-img (getfiled "Выбор файла" (getvar "DWGPREFIX") "*" 0))
  (setq patch-dat (strcat (vl-filename-directory patch-img)"\\"(vl-filename-base patch-img)".dat"))
  (if (file_check patch-dat)
    (progn
      (foreach x (file_read_to_list patch-dat)
	(setq list-dat (append list-dat (list (convert-string-to-list-be-delimiter x ","))))
	)
      (setq bl-p1 (list (atof(nth 1 (nth 1 list-dat)))(atof(nth 0 (nth 1 list-dat)))))
      (setq bl-p2 (list (atof(nth 1 (nth 2 list-dat)))(atof(nth 0 (nth 2 list-dat)))))
      (setq bl-p3 (list (atof(nth 1 (nth 3 list-dat)))(atof(nth 0 (nth 3 list-dat)))))
      (setq bl-p4 (list (atof(nth 1 (nth 4 list-dat)))(atof(nth 0 (nth 4 list-dat)))))
      
      (if (setq dialog-var(dialog-print_to_png_area))
	(progn
	  (setq xy-p1 (convert-bl-wgs-84-to-xy-by-property dialog-var bl-p1))
	  (setq xy-p2 (convert-bl-wgs-84-to-xy-by-property dialog-var bl-p2))
	  (setq xy-p3 (convert-bl-wgs-84-to-xy-by-property dialog-var bl-p3))
	  (setq xy-p4 (convert-bl-wgs-84-to-xy-by-property dialog-var bl-p4))
;;;	  (draw-lwpolyline-vla-by-list-property
;;;	    (list(cons "spece" (if (eq (getvar "CTAB")"Model")model_spece paper_spece))
;;;		 (cons "Coordinates" (list xy-p1 xy-p2 xy-p3 xy-p4))
;;;		 (cons "Closed" -1)
;;;		 ))
	  (vla-StartUndoMark active_document)
	  (create-or-sel-layer (strcat "Растр "(vl-filename-base patch-img)))
	  (command "-image" "_attach" patch-img (mapcar '+ xy-p4 (list (/(abs(-(distance xy-p4 xy-p3)(distance xy-p1 xy-p2)))4.0) (/(abs(-(distance xy-p1 xy-p4)(distance xy-p2 xy-p3)))4.0))) "1" "0")
	  (setq obj (vlax-ename->vla-object (entlast)))
	  (vla-put-ImageHeight obj (/(+(distance xy-p1 xy-p4)(distance xy-p2 xy-p3))2.0))

	  (vla-put-ImageWidth obj (/(+(distance xy-p1 xy-p2)(distance xy-p4 xy-p3))2.0))

	  (vla-put-Rotation obj (/(+(angle xy-p4 xy-p3)(angle xy-p1 xy-p2))2.0))
	  (vla-EndUndoMark active_document)
	  (princ (strcat "\nОриентировочная точность вставки по вертикали=" (rtos (/(abs(-(distance xy-p1 xy-p4)(distance xy-p2 xy-p3)))4.0) 2 3) "м"))
	  (princ (strcat "\nОриентировочная точность вставки по горизонтали=" (rtos (/(abs(-(distance xy-p4 xy-p3)(distance xy-p1 xy-p2)))4.0) 2 3) "м"))
	  )
	)
      )
    (alert (strcat "Не найден файл: \n" patch-dat
		   "\nбез него никак!"))
    )
  (princ)
  )