;|
   命令：wkz_txt
   功能：自动给挖孔桩排序号wkz_txt，标注出来，排序按照 桩径，扩大头直接排升序
        标注后将会和桩块制作成一个匿名组。
 
|;

(defun c:wkz_txt (/ wkz_lyr wkz_txt_prefix wkz_txt_len1 wkz_txt_len2
		    wkz_txt_height wkz_txt_angle ss wkz_l zj kdzj old old1
		    new e i n m nn wkz_ll p1 p2 p3
		 )
  (mai_start nil)
  (mai_get_scale)
  (setq mai_wkz_text (cond (mai_wkz_text) ((list "WKZ-text" "3"))))
  (princ "\n选择需要排序号的挖孔桩:")
  (setq ss (ssget (list '(0 . "insert") '(2 . "wkz_*"))))
  (if (not ss) (exit))
  (if (not #wkz_txt_prefix) (setq #wkz_txt_prefix "WKZ-"))
  (setq wkz_txt_prefix (getstring (strcat "\n请输入挖孔桩标注前缀<" #wkz_txt_prefix ">:")))
  (if (= "" wkz_txt_prefix) (setq wkz_txt_prefix #wkz_txt_prefix))
  (setq wkz_txt_prefix (strcase wkz_txt_prefix)
        wkz_txt_len1 (* mai_scale 15)	       ; 斜线长度
	    wkz_txt_len2 (* mai_scale 18)	       ; 水平线长度
	    wkz_txt_height (* mai_scale (nth 3 maitextname))	       ; 字高
	    wkz_txt_angle (/ pi 3)     ; 斜线角度(第一象限)
		ss (mai_ssget_2_list ss)
  )

  (foreach e ss
    (setq etb (entget e)
		  ename (mai_dxf 2 etb)
    )
	(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 (cons kdzj (cons e (cdr old1))) old1 (cdr old)))
	                  (cons zj (cons (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
	)
  )
	(apply 'mai_create_layer mai_wkz_text)
    (foreach n wkz_l
	  (setq wkz_ll (vl-sort (cdr n) '(lambda (x y) (< (car x) (car y)))))
	  (foreach m wkz_ll
	     (setq i (1+ i))
	     (foreach nn (cdr m)
	        (setq ob_mask (entlast))
	        (setq p1 (trans (mai_dxf 10 nn) 0 1)
		          p2 (polar p1 wkz_txt_angle (- wkz_txt_len1))
		          p3 (polar p2 0 (- wkz_txt_len2))
	        )
	        (mai_entmake "lwpolyline" (list p1 p2 p3))
		    (mai_draw_text "bl" (polar p3 (/ pi 2) (* mai_scale 0.15)) wkz_txt_height 0 (strcat wkz_txt_prefix (itoa i)) (nth 2 maitextname) nil 0.8)
	        (setq ss (mai_newset ob_mask))
			(ssadd nn ss)
	        (mai_group_creat ss)
	      )
	  )
   )
   (mai_end)
)
