	; 命令：mini_wkz_txt
	; 功能：
		; 自动给挖孔桩排序号[mini_wkz_txt]，标注出来，排序按照 桩径，扩大头直接排升序

(apply
	'(lambda( / x )
		(or mai_pile_text
			(not (setq x (mai_panel_search "谜你结构专业设置文件[mini_jiegou_config].lsp")))
			(load x)
		)
	)
	nil
)

(defun c:mini_wkz_txt ( / old_cmd 
							ss wkz_l zj kdzj old old1
						new e i m wkz_ll p1 p2 ename
					)
	(mini_start nil)
	(mai_last_com "mini_zjfsj")
	(mai_get_scale)
	(setq ss
			(mai_select_first
				(list '(0 . "insert") '(2 . "wkz_*x*"))
				"选择需要排序号的挖孔桩:<退出>"
				"没有找到挖孔桩."
			)
	)
	(or mai_wkz_txt (setq mai_wkz_txt "WKZ-"))
	(or
		(mai_not_str (setq e (getstring (strcat "\n请输入挖孔桩标注前缀:<" mai_wkz_txt ">"))))
		(setq mai_wkz_txt e)
	)
	(setq
		mai_wkz_txt (strcase mai_wkz_txt)
		ss (mai_ssget_2_list ss)
	)

	(foreach e ss
		(setq ename (mai_dxf 2 e))
		(mapcar 'set '(zj kdzj) (mai_str2lst1 (cadr (mai_str2lst ename "_")) "X"))
		(if (setq old (assoc zj wkz_l))
			(setq new
					(if (setq old1 (assoc kdzj (cdr old)))
						(cons zj (subst (vl-list* kdzj e (cdr old1)) old1 (cdr old)))
						(vl-list* zj (list kdzj e) (cdr old))
					)
					wkz_l
					(subst new old wkz_l)
			)
			(setq wkz_l (cons (list zj (list kdzj e)) wkz_l))
		)
		(setq
			wkz_l (vl-sort wkz_l '(lambda (x y) (< (car x) (car y))))
			i 0
		)
	)
	(foreach wkz_ll wkz_l
		(setq wkz_ll (vl-sort (cdr wkz_ll) '(lambda (x y) (< (car x) (car y)))))
		(foreach m wkz_ll
			(setq i (1+ i))
			(foreach p1 (cdr m)
				(setq
					p1 (trans (mai_dxf 10 p1) 0 1)
					p2 (polar p1 (* pi 1.75) (* mai_scale2 15))
				)
				(mai_create_mleader
					mai_pile_text
					mai_mleader_arrow_block
					1
					(list (nth 2 maitextname) (nth 3 maitextname))
					(strcat mai_wkz_txt (itoa i))
					(list p1 p2)
					nil
				)
			)
		)
	)
	(mai_end)
)
