; 由离散点生成三角网[mini_triangle].lsp


(or mai_cehui_gcd_blk
	(mai_load_files (mai_panel_search "谜你测绘功能设置文件.lsp"))
)

; (defun c:mini_triangle ( / old_cmd t0 sss pts)
	; (mai_start nil)
	; (mai_last_com "mini_triangle")
	; (setq t0 (car (mai_entsel nil "选择一个实体并获得块或点的图层名:" "选择的不是实体." '((0 . "insert,point")) nil)))
	; (or t0 (exit))
	; (setq pts
			; (mai_select_first
				; (list (cons 0 "insert,point") (assoc 8 (entget t0)))
				; "选择要由离散点生成三角网triangle地形的块或点:<回车退出>"
				; "没有找到任何块或点."
			; )
	; )
	; (princ "\n数据处理中......")
	; (setq t0 (getvar "TDUSRTIMER"))
	; (setq
		; pts (mapcar '(lambda(x)(setq x (entget x))(trans (mai_dxf 10 x) (mai_dxf 210 x) 1 T)) (mai_ssget_2_list pts))
		; sss (mai_points_triangle pts)
	; )
	; (princ (strcat "\n用时" (rtos (* (- (getvar "TDUSRTIMER") t0) 86400) 2 4) "秒"))
	; (apply 'mai_create_layer mai_triangle_layer)
	; (mapcar '(lambda (x) (mai_a_triangle (mapcar '(lambda (y)(nth y pts)) x) nil T)) sss)
	; (princ (strcat "\n用时" (rtos (* (- (getvar "TDUSRTIMER") t0) 86400) 2 4) "秒"))
	; (mai_end)
; )

; (defun c:mini_old_triangle ( / old_cmd t0 ss pts)
	; (mai_start nil)
	; (mai_last_com "mini_old_triangle")
	; (setq t0 (car (mai_entsel nil "选择一个实体并获得块或点的图层名:" "选择的不是实体." '((0 . "insert,point")) nil)))
	; (or t0 (exit))
	; (setq pts
			; (mai_select_first
				; (list (cons 0 "insert,point") (assoc 8 (entget t0)))
				; "选择要由离散点生成三角网triangle地形的块或点:<回车退出>"
				; "没有找到任何块或点."
			; )
	; )
	; (princ "\n数据处理中......")
	; (setq
		; pts (mapcar '(lambda(x)(setq x (entget x))(trans (mai_dxf 10 x) (mai_dxf 210 x) 1 T)) (mai_ssget_2_list pts))
		; ss (mai_points_triangle pts)
	; )
	; (apply 'mai_create_layer mai_triangle_layer)
	; (mapcar '(lambda (x) (mai_a_triangle (mapcar '(lambda (y)(nth y pts)) x) nil T)) ss)
	; (mai_end)
; )

(defun c:mini_triangle ( / old_cmd t0 ss pts)
	(mai_start nil)
	(mai_last_com "mini_triangle")
	(setq t0 (car (mai_entsel nil "选择一个块获取块名和图层名或点获取图层:" "选择的不是块或点." '((0 . "insert,point")) nil)))
	(or t0 (exit))
	(setq
		t0 (entget t0)
		ss
			(mai_select_first
				(vl-remove nil (list (cons 0 "insert,point") (cond ((assoc 2 t0))) (assoc 8 t0)))
				"选择高程块:<回车退出>"
				"没有找到任何块."
			)
		t0 nil
	)
	(mai_make_panel_up
		(list "高程块修改面板"
			(list
				"选择功能"
				nil
				(list "由高程块生成三角网" "(setq t0 0)")
				nil
				(list "按Z坐标设置高程块属性" "(setq t0 1)")
				nil
				(list "按块属性设置高程块Z坐标" "(setq t0 2)")
				nil
				(list "高程块Z坐标改为0" "(setq t0 3)")
			)
		)
	)
	(or t0 (exit))
	(setq ss (mai_ssget_2_list ss))
	(cond
		(	(= t0 0)
			(princ "\n数据处理中......")
			(setq
				pts (mapcar '(lambda(x)(setq x (entget x))(trans (mai_dxf 10 x) (mai_dxf 210 x) 1 T)) ss)
				ss (mai_points_triangle pts)
			)
			(apply 'mai_create_layer mai_triangle_layer)
			(mapcar '(lambda (x) (mai_a_triangle (mapcar '(lambda(y)(nth y pts)) x) nil T)) ss)
		)

		(	(= t0 1)
			(mapcar
				'(lambda(x / att txt elst )
					(setq
						att (entget x)
						txt (rtos (caddr (trans (mai_dxf 10 att) (mai_dxf 210 att) 0 T)) 2 2)
						att (vl-string-search "." txt)
						txt (if att
								(substr (strcat txt "00") 1 (+ 3 att))
								(strcat txt ".00")
							)
						att (caar (mai_get_blk_atts x nil))
					)
					(if att
						(progn
							(setq
								elst (entget att)
								elst (subst (cons 2 txt) (assoc 2 elst) elst)
							)
							(entmod elst)
							(entupd att)
						)
					)
				)
				(vl-remove-if '(lambda(x)(= (mai_dxf 0 x) "POINT")) ss)
			)
		)

		(	(= t0 2)
			(mapcar
				'(lambda(x / att txt elst nor pt1 pt2 )
					(setq
						elst (entget x)
						att (caddar (mai_get_blk_atts x nil))
					)
					(if att
						(progn
							(setq
								nor (mai_dxf 210 elst)
								pt1 (trans (mai_dxf 10 elst) nor 0 T)
								pt2 (list (car pt1) (cadr pt1) (atof att))
								pt2 (trans pt2 0 nor T)
								elst (subst (cons 10 pt2) (assoc 10 elst) elst)
							)
							(entmod elst)
						)
					)
				)
				(vl-remove-if '(lambda(x)(= (mai_dxf 0 x) "POINT")) ss)
			)
		)

		(	(= t0 3)
			(mapcar
				'(lambda(x / att txt elst nor pt1 pt2 )
					(setq
						elst (entget x)
						nor (mai_dxf 210 elst)
						pt1 (trans (mai_dxf 10 elst) nor 0 T)
						pt2 (list (car pt1) (cadr pt1) 0)
						pt2 (trans pt2 0 nor T)
						elst (subst (cons 10 pt2) (assoc 10 elst) elst)
					)
					(entmod elst)
				)
				(vl-remove-if '(lambda(x)(= (mai_dxf 0 x) "POINT")) ss)
			)
		)

	)
	(mai_end)
)
