(defun C:draw_table_coord_trassy_to_offset ( / 2DPLINE_VLA  DISKRIPTION DISKRIPTION_LIST FLAG LEADERS_LIST LIST-SETTINGS MLEADER_OBJ MODEL_SPECE NABOR NN NUM_ROW NUM_VINOSKA P P1 P3 PLINE POINT_LEADERS_LIST POINT_LIST PT_ARRAY SPISOK T0 TABLE_OBJ VLA_VINOSKA X)
  ; выводит каталог координат полилинии в таблицу
  (geo_tools-help "draw_table_coord_trassy_to_offset")
  (load_global_variable)
  (setq flag-angle T)
  (setq list-settings(get-list-serttings-by-table-coord-polyline))
  (initget 1)(setq pline (car (entsel "\nВыбери полилинию трассы: ")))
  (cond
    ((eq pline nil)
     (alert "Ничего не выбрано!"))
    ((not(eq (cdr(assoc 0 (entget pline))) "LWPOLYLINE"))
     (alert "Выбрана не 2D полилиния!"))
    ((eq (cdr(assoc 0 (entget pline))) "LWPOLYLINE")
     (vla-StartUndoMark active_document)
     (create-table-style);создает стиль таблиц каталога координат
     (create-mleader-style "Подписи");создает стиль мвыносок
     (setq 2Dpline_vla (vlax-ename->vla-object pline))
     (setq spisok (extract_coord_lwpolyline (entget pline)))
     (while (not flag)
       (initget 1 "Добавить Настройка Выход")(setq t0 (getpoint "\nУкажи точку вставки таблицы координат [Добавить к старой/Настройка/Выход]: "))
       (cond
	 ((eq t0 "Выход")
	  (setq flag T))
	 ((eq t0 "Добавить")
	  (initget 1)(setq table_obj (car (entsel "\nВыбери существующую таблицу с координатами: ")))
	  (if table_obj
	    (progn
	      (setq table_obj (vlax-ename->vla-object table_obj))
	      (if (=(get-item-by-name-in-list list-settings"auto-numering")1)
		(setq nn (1+(atoi(vla-GetText table_obj (-(vla-get-rows table_obj)3) 0 ))))
		(setq nn (get-item-by-name-in-list list-settings"first-number"))
		)
	      )
	    (progn
	      (princ "\nТаблица не выбрана.")
	      (setq t0 "Выход")
	      )
	    )
	  (setq flag T)
	  )
	 ((eq t0 "Настройка")
	  (dialog-settings-create-table)
	  (setq list-settings(get-list-serttings-by-table-coord-polyline))
	  (setq flag nil)
	  )
	 (T
	  (setq table_obj (vla-AddTable model_spece (vlax-3D-point t0) 2 (if (=(get-item-by-name-in-list list-settings"angle-column")1) 6 5) 12 20))
	  (vla-put-StyleName table_obj "Координаты")
	  (vla-SetColumnWidth table_obj 0 8)
	  
	  (vla-SetText table_obj 0 0 (vla-get-Layer 2Dpline_vla))
	  (vla-SetCellTextHeight table_obj 0 0 4.0)
	  (vla-SetCellAlignment table_obj 0 0 acMiddleCenter)
	  (vla-SetText table_obj 1 0 "№\nп/п")
	  (vla-SetCellTextHeight table_obj 1 0 2.8)
	  (vla-SetCellAlignment table_obj 1 0 acMiddleCenter)
	  (vla-SetText table_obj 1 1 " Наимено-\n вание")
	  (vla-SetCellAlignment table_obj 1 1 acMiddleLeft)
	  (vla-SetCellTextHeight table_obj 1 1 2.4)
	  (vla-SetText table_obj 1 2 "X")
	  (vla-SetCellAlignment table_obj 1 2 acMiddleCenter)
	  (vla-SetCellTextHeight table_obj 1 2 2.8)
	  (vla-SetText table_obj 1 3 "Y")
	  (vla-SetCellAlignment table_obj 1 3 acMiddleCenter)
	  (vla-SetCellTextHeight table_obj 1 3 2.8)
	  (vla-SetText table_obj 1 4 "Длина\nлинии")
	  (vla-SetCellAlignment table_obj 1 4 acMiddleCenter)
	  (vla-SetCellTextHeight table_obj 1 4 2.8)
	  
	  (if (=(get-item-by-name-in-list list-settings"angle-column")1)
	    (progn
	      (vla-SetText table_obj 1 5 "Угол")
	      (vla-SetCellAlignment table_obj 1 5 acMiddleCenter)
	      (vla-SetCellTextHeight table_obj 1 5 2.8)
	      (vla-SetColumnWidth table_obj 5 25.0)
	      )
	    )
	  
	  (vla-put-horzcellmargin table_obj 0.5)
	  (vla-put-vertcellmargin table_obj 0.5)
	  (vla-SetRowHeight table_obj 1 12.0)
	  (setq nn (get-item-by-name-in-list list-settings"first-number"))
	  (setq flag T)
	  )
	 )
       ); while настройка или выбор/создание таблицы
     (if (/= t0 "Выход")
       (progn
	 (if (=(get-item-by-name-in-list list-settings"mleader-enable")1); если использование мвыносок включено формируем списки мвыносок и точек куда они указывают
	   (if (setq nabor (ssget "_X" '((0 . "MULTILEADER"))))
	     (progn
	       (setq leaders_list (convert_ss_to_list nabor))
	       (mapcar '(lambda (x)
			  (setq point_list (vlax-safearray->list(vlax-variant-value(vla-GetLeaderLineVertices (vlax-ename->vla-object x) 0))))
			  (setq point_leaders_list (append point_leaders_list (list (list (car point_list)(cadr point_list)))))
			  )
		       leaders_list)
	       )
	     )
	   )
	 (mapcar '(lambda (x); обработка списка точек полилинии
		    (if (=(get-item-by-name-in-list list-settings"mleader-enable")1); если использование мвыносок включено
		      (setq num_vinoska (analysis_member_point_in_list_equal x point_leaders_list 0.01)); анализ попадания точки списка на ногу мвыноски
		      )
		    (if num_vinoska
		      (progn
			(setq vla_vinoska (vlax-ename->vla-object (nth num_vinoska leaders_list)))
			(if (eq (vla-get-ContentBlockName vla_vinoska) "")
			  (setq diskription (vla-get-TextString vla_vinoska))
			  (setq diskription (strcat
					      (if (=(get-item-by-name-in-list list-settings"add-perfix-to-mleader")1)
						(get-item-by-name-in-list list-settings"perfix")
						""
						)
					      (cadr(extract_302 (entget (nth num_vinoska leaders_list)))))))
			)
		      (progn
			(setq diskription "нет")
			(setvar "CMLEADERSTYLE" "Подписи")
			(cond
			  ((eq (vl-position x spisok) 0) ; первая точка в списке
			   (setq pt_array (convert_coords_list_from_safearray_mleader (list x (polar x (angle (nth (1+(vl-position x spisok))spisok) x)(/ 10 (getvar "CANNOSCALEVALUE"))))))
			   (setq mleader_obj (vla-addmleader model_spece pt_array 0))
			   (vla-put-StyleName mleader_obj "Подписи")
			   (vla-put-textstring mleader_obj (itoa nn))
			   (vla-put-TextHeight mleader_obj (/ 3 (getvar "CANNOSCALEVALUE")))
			   (vla-put-ArrowheadType mleader_obj 12)
			   (vla-put-ArrowheadSize mleader_obj (/ 1.5 (getvar "CANNOSCALEVALUE")))
			   (vla-put-ArrowheadBlock mleader_obj "_DotBlank")
			   )
			  ((eq (vl-position x spisok) (1-(length spisok))); последняя точка в списке
			   (setq pt_array (convert_coords_list_from_safearray_mleader (list x (polar x (angle (nth (1-(vl-position x spisok))spisok) x)(/ 10 (getvar "CANNOSCALEVALUE"))))))
			   (setq mleader_obj (vla-addmleader model_spece pt_array 0))
			   (vla-put-StyleName mleader_obj "Подписи")
			   (vla-put-textstring mleader_obj (itoa nn))
			   (vla-put-TextHeight mleader_obj (/ 3 (getvar "CANNOSCALEVALUE")))
			   (vla-put-ArrowheadType mleader_obj 12)
			   (vla-put-ArrowheadSize mleader_obj (/ 1.5 (getvar "CANNOSCALEVALUE")))
			   (vla-put-ArrowheadBlock mleader_obj "_DotBlank")
			   )
			  (T ; все осальные точки списка
			   (setq p1(nth(1-(vl-position x spisok))spisok))
			   (setq p3(nth(1+(vl-position x spisok))spisok))
			   (cond
			     ((> (calculation_angle_be_3points p1 x p3) (calculation_angle_be_3points p3 x p1))
			      (setq p (polar x (+(angle x p3) (/(calculation_angle_be_3points p1 x p3)2)) (/ 10 (getvar "CANNOSCALEVALUE")))))
			     ((< (calculation_angle_be_3points p1 x p3) (calculation_angle_be_3points p3 x p1))
			      (setq p (polar x (+(angle x p1) (/(calculation_angle_be_3points p3 x p1)2)) (/ 10 (getvar "CANNOSCALEVALUE")))))
			     ((= (calculation_angle_be_3points p1 x p3) (calculation_angle_be_3points p3 x p1))
			      (setq p (polar x (+(angle x p3) (/ pi 2)) (/ 10 (getvar "CANNOSCALEVALUE"))))))
			   
			   (setq pt_array (convert_coords_list_from_safearray_mleader (list x p)))
			   (setq mleader_obj (vla-addmleader model_spece pt_array 0))
			   (vla-put-StyleName mleader_obj "Подписи")
			   (vla-put-textstring mleader_obj (itoa nn))
			   (vla-put-TextHeight mleader_obj (/ 3 (getvar "CANNOSCALEVALUE")))
			   
			   (vla-put-ArrowheadType mleader_obj 12)
			   (vla-put-ArrowheadSize mleader_obj (/ 1.5 (getvar "CANNOSCALEVALUE")))
			   (vla-put-ArrowheadBlock mleader_obj "_DotBlank")
			   )
			  )
			)
		      )
		    (setq diskription_list (append diskription_list (list diskription)))
		    (setq num_row (vla-get-rows table_obj))
		    (vla-InsertRows table_obj (1+ num_row) 4 2)
		    (vla-SetRowHeight table_obj (1+ num_row) 5.2)
		    (vla-mergeCells table_obj num_row (1+ num_row) 0 0)
		    (vla-mergeCells table_obj num_row (1+ num_row) 1 1)
		    (vla-mergeCells table_obj num_row (1+ num_row) 2 2)
		    (vla-mergeCells table_obj num_row (1+ num_row) 3 3)
		    (vla-SetText table_obj num_row 0 (rtos nn 2 0))
		    (vla-SetCellAlignment table_obj num_row 0 acMiddleCenter)
		    (vla-SetCellTextHeight table_obj num_row 0 2.8)
		    (vla-SetText table_obj num_row 1 diskription)
		    (vla-SetCellAlignment table_obj num_row 1 acMiddleLeft)
		    (vla-SetCellTextHeight table_obj num_row 1 2.4)
		    (vla-SetText table_obj num_row 2 (rtos (nth 1 x) 2 (get-item-by-name-in-list list-settings"accuracy-coordinate")))
		    (vla-SetCellAlignment table_obj num_row 2 acMiddleCenter)
		    (vla-SetCellTextHeight table_obj num_row 2 2.8)
		    (vla-SetText table_obj num_row 3 (rtos (nth 0 x) 2 (get-item-by-name-in-list list-settings"accuracy-coordinate")))
		    (vla-SetCellAlignment table_obj num_row 3 acMiddleCenter)
		    (vla-SetCellTextHeight table_obj num_row 3 2.8)
		    (vla-SetRowHeight table_obj (1+ num_row) 5.0)
		    (vla-SetRowHeight table_obj num_row 5.0)
		    (if (not(eq (vl-position x spisok) 0))
		      (progn
			(vla-mergeCells table_obj (1- num_row) num_row 4 4)
			(vla-SetCellAlignment table_obj (1- num_row) 4 acMiddleCenter)
			(vla-SetCellTextHeight table_obj (1- num_row) 4 2.8)
			(vla-SetText table_obj (1- num_row) 4 (rtos(distance x(nth (1-(vl-position x spisok))spisok))2 (get-item-by-name-in-list list-settings"accuracy-coordinate")))
			))
		    (if (=(get-item-by-name-in-list list-settings"angle-column")1)
		      (progn
			(if(or(eq (vl-position x spisok) 0)(eq (vl-position x spisok) (1-(length spisok)))) ; первая точка в списке или последняя точка в списке
			  (setq string "-----")
			  (progn
			    (setq p1(nth(1-(vl-position x spisok))spisok))
			    (setq p3(nth(1+(vl-position x spisok))spisok))
			    (setq angle-l (convert-rad-grad(-(calculation_angle_be_3points p1 x p3)pi)))
			    (setq string (strcat (if (minusp angle-l) "Л" "П") " " (vl-string-subst"%%d" "d"(convert-dec-to-gms-str (abs angle-l) 2)0)))
			    )
			  )
			(vla-mergeCells table_obj num_row (1+ num_row) 5 5)
			(vla-SetText table_obj num_row 5 string)
			(vla-SetCellAlignment table_obj num_row 5 acMiddleCenter)
			(vla-SetCellTextHeight table_obj num_row 5 2.8)
			)
		      )
		    (setq nn (1+ nn))
		    )
		 spisok)

	 (setq num_row (vla-get-rows table_obj))
	 (vla-InsertRows table_obj (1+ num_row) 8 1)
	 (vla-mergeCells table_obj num_row num_row 0 3)
	 (vla-mergeCells table_obj (1- num_row) num_row 4 4)
	 (vla-SetText table_obj (1- num_row) 4 (strcat "\U+03A3L="(rtos (vlax-curve-getDistAtPoint 2Dpline_vla (vlax-curve-getEndPoint 2Dpline_vla)) 2 (get-item-by-name-in-list list-settings"accuracy-coordinate")) "м"))
	 (vla-SetCellTextHeight table_obj (1- num_row) 4 2.4)
	 (vla-SetCellAlignment table_obj (1- num_row) 4 acMiddleCenter)
	 (vla-SetText table_obj num_row 0 (strcat "Длина трассы = "(rtos (vlax-curve-getDistAtPoint 2Dpline_vla (vlax-curve-getEndPoint 2Dpline_vla)) 2 (get-item-by-name-in-list list-settings"accuracy-coordinate")) "м"))
	 (vla-SetCellTextHeight table_obj num_row 0 2.8)
	 (vla-SetRowHeight table_obj num_row 8.0)
	 (vla-SetCellAlignment table_obj num_row 0 acMiddleCenter)
	 )
       )
     (vla-EndUndoMark active_document)
     )
    )
  (princ)
  )

(defun dialog-settings-create-table (/ dcl_id list-settings)
  (setq dcl_id (geo-tools-load-dialog "dialog_settings_table_by_polyline"))
  (new_dialog "dialog_settings_table_by_polyline" dcl_id)
  (setq list-settings(get-list-serttings-by-table-coord-polyline))
  (foreach x list-settings
    (set_tile (car x) (convert-item-in-string (cadr x) 2))
    )
  (if(= (get-item-by-name-in-list list-settings "mleader-enable") 0)
    (progn
      (mode_tile "add-perfix-to-mleader" 1)
      (mode_tile "perfix" 1)
      )
    (progn
      (mode_tile "add-perfix-to-mleader" 0)
      (mode_tile "perfix" 0)
      (if (= (get-item-by-name-in-list list-settings"add-perfix-to-mleader") 0)
	(mode_tile "perfix" 1)
	(mode_tile "perfix" 0)
	)
      )
    )
  (action_tile "mleader-enable"
    (vl-prin1-to-string
      '(progn
	(setq list-settings (put-item-by-name-in-list list-settings "mleader-enable"(atoi $value)))
	(if(= (get-item-by-name-in-list list-settings "mleader-enable") 0)
	 (progn
	  (mode_tile "add-perfix-to-mleader" 1)
	  (mode_tile "perfix" 1)
	  )
	 (progn
	  (mode_tile "add-perfix-to-mleader" 0)
	  (mode_tile "perfix" 0)
	  (if (= (get-item-by-name-in-list list-settings"add-perfix-to-mleader") 0)
	   (mode_tile "perfix" 1)
	   (mode_tile "perfix" 0)
	   )
	  )
	 )
	)
      )
    )
  (action_tile "add-perfix-to-mleader"
    (vl-prin1-to-string
      '(progn
	(setq list-settings (put-item-by-name-in-list list-settings "add-perfix-to-mleader"(atoi $value)))
	(if (= (get-item-by-name-in-list list-settings"add-perfix-to-mleader") 0)
	 (mode_tile "perfix" 1)
	 (mode_tile "perfix" 0)
	 )
	)
      )
    )
  (action_tile "perfix"
    (vl-prin1-to-string
      '(setq list-settings (put-item-by-name-in-list list-settings "perfix" $value))
      )
    )
  
  (action_tile "auto-numering"
    (vl-prin1-to-string
      '(setq list-settings (put-item-by-name-in-list list-settings "auto-numering" (atoi $value)))
      )
    )
  
  (action_tile "first-number"
    (vl-prin1-to-string
      '(setq list-settings (put-item-by-name-in-list list-settings "first-number" (atoi $value)))
      )
    )
  (action_tile "accuracy-coordinate"
    (vl-prin1-to-string
      '(setq list-settings (put-item-by-name-in-list list-settings "accuracy-coordinate" (atoi $value)))
      )
    )
  (action_tile "angle-column"
    (vl-prin1-to-string
      '(setq list-settings (put-item-by-name-in-list list-settings "angle-column" (atoi $value)))
      )
    )
  (if (= (start_dialog) 1)
    (put-list-serttings-by-table-coord-polyline list-settings))
  (unload_dialog dcl_id)
  (princ)
  )

(defun get-list-serttings-by-table-coord-polyline (/ output-list)
  (setq output-list (vlax-ldata-get "geo_tools_dictionary" "list-serttings-by-table-coord-polyline"))
  (if (get-item-by-name-in-list list-settings"angle-column")
    output-list
    (list
      (list "mleader-enable" 1)
      (list "add-perfix-to-mleader" 1)
      (list "perfix" "т.")
      (list "auto-numering" 1)
      (list "first-number" 1)
      (list "accuracy-coordinate" 2)
      (list "angle-column" 0)
      )
    )
  )
(defun put-list-serttings-by-table-coord-polyline (input-list / )
  (vlax-ldata-put "geo_tools_dictionary" "list-serttings-by-table-coord-polyline" input-list)
  )