;PKPM配筋归并，速度是比较快的那种，关键是归并对象选择要快。曾经还考虑过沿竖向标高（按WMASS.OUT结果）插入并提示归并，
;代码也不困难，木时间确切说是不想搞，木有什么意思。


;PKPM梁配筋图归并;
(setq liangpeijin (list "wpj_beam" "3"))

(defun c:LGB() (PKPMBeam))
(defun pkpmbeam( / pickboxwucha_beam guibingn wpjdwgposition pt1 pt10 pt11 pt12 pt13 temppt
                    wpjbeam1 wpjbeam2 ptbtemp index n wpjtextent wpjtext wpjtextheight wpjtextangle
			  )
  (princ "\nPKPM梁配筋图归并程序")
  (setq GuiBingN (getint "\n请输入要归并的层数:")
		GuiBingN (if GuiBingN (1- GuiBingN) 0)
        PT1 (getpoint "\n请输入首层归并图纸参考坐标特征点:")
        index 1
  )
  (repeat GuiBingN
      (setq index (+ index 1)
            TempPT (getpoint (strcat "\n请输入第" (itoa index) "层配筋计算简图定位特征点:"))
            WPJdwgPosition (cons TempPT WPJdwgPosition);得到其余层定位特征点;
	  )
  )
  (alert "\n层定位已完成,下面输入两点供框选首层配筋图纸.")
  (setq WPJdwgPosition (reverse WPJdwgPosition)
        PT10 (getpoint "\n下面输入两点供框选首层配筋图纸,请输入第一点:")
  )
  (if pt10
      (setq PT11 (getcorner pt10 "\n请输入第二点:"))
	  (exit)
  )
  (setq WPJBeam1 (ssget "C" PT10 PT11 '((0 . "text") (8 . "21000") (1 . "*-*"))))
  (apply 'mai_create_layer liangpeijin)
  (command ".chprop" WPJBeam1 "" "layer" (car liangpeijin) "")
  (command ".zoom" "e")
  (foreach tmp WPJdwgPosition
    (setq PtbTemp (PanPtbXYZ (list PT10 PT11) PT1 tmp)
          WPJBeam2 (ssget "C" (car PtbTemp) (cadr PtbTemp)  '((0 . "text") (8 . "21000") (1 . "*-*")))
	)
	(if WPJBeam2
	    (progn (command ".copy" WPJBeam2 "" "non" tmp "non" PT1)
               (mai_entmake "line" PtbTemp)
        ) 
    ) 
  ) 
  ;end repeat,把后面要归并的梁配筋文字移动到首层位置了;

  (setq PickBoxWuCHa_Beam (/ (mai_dxf 40 (ssname WPJBeam1 0)) 3) ;由配筋文字大小得到选择框误差大小;
        N (sslength WPJBeam1)
        index 0
  )
  (repeat N
    (setq pt1 (ssname WPJBeam1 index)
          index (1+ index)
          WpjText (mai_dxf 1 pt1)
		  pt1 (mapcar 'car (mai_data_entget2pline pt1))
		  pt1 (cons (last pt1) pt1)
		  pt1 (mai_fence_Offset pt1 PickBoxWuCHa_Beam (mai_point_divide (car pt1) (cadr pt1) 1.5))
		  pt2 (cond ((wcmatch WpjText "G*") WpjText) ;箍筋;
                    ((wcmatch WpjText "VT*") WpjText) ;扭筋;
                    ("*-*-*") ;梁面筋或底筋;
		      )
		  pt3 (cond ((wcmatch WpjText "G*") "AsG") ;箍筋;
                    ((wcmatch WpjText "VT*") "AsT") ;扭筋;
                    ("As") ;梁面筋或底筋;
		      )
          WPJBeam2 (ssget "cp" pt1 (list (cons 0 "text") (cons 8 "21000") (cons 1 pt2)));取得其它层箍筋;
	)
    (if WPJBeam2 (MAXWpjAs_Beam pt3 WpjTextEnt WPJBeam2)) ;如果有选择到就在选出max值赋予WpjTextEnt
  )
  (princ)
  )

;PKPM柱配筋图归并;
(defun c:ZGB() (PKPMColumn))

(defun PKPMColumn ( / PickBoxWuCHa_Column GuiBingN WPJdwgPosition PT1 PT10 PT11 PT12 PT13 TempPT
                     WPJColumn WPJColumn2 PtbTemp index N WpjTextEnt WpjText WpjTextHeight WpjTextAngle
				  )
  (princ "\nPKPM柱配筋图归并程序")
  (setq GuiBingN (getint "\n请输入要归并的层数:")
        index 1
        GuiBingN (if GuiBingN (1- GuiBingN) 0)
        PT1 (getpoint "\n请输入首层归并图纸参考坐标特征点:")
  )
  (repeat GuiBingN
      (setq index (+ index 1)
            TempPT (getpoint (strcat "\n请输入第" (itoa index) "层配筋计算简图定位特征点:"))
            WPJdwgPosition (append WPJdwgPosition (list TempPT));得到其余层定位特征点;
	  )
  )
  (alert "\n层定位已完成,下面输入两点供框选首层配筋图纸.")
  (setq PT10 (getpoint "\n下面输入两点供框选首层配筋图纸,请输入第一点:")
        PT11 (getcorner pt10 "\n请输入第二点:")
        WPJColumn (ssget "C" PT10 PT11 '((0 . "text") (8 . "22000")))
        WPJZHouYaBi (ssget "C" PT10 PT11 '((0 . "text") (8 . "28000")))
        index 0
  )
  (if (not GBColor);归并颜色;
      (setq Oldcecolor (getvar "cecolor")
            GBColor (acad_colordlg 7)
	  )
  )
  (mai_create_layer "WPJ_Column" GBcolor)
  (mai_create_layer "WPJ_ZHYB" GBcolor)
  (setvar "cecolor" Oldcecolor)
  (command ".chprop" WPJColumn "" "layer" "WPJ_Column" "")
  (command ".chprop" WPJZHouYaBi "" "layer" "WPJ_ZHYB" "")
  (command ".zoom" "e")
  (repeat (length WPJdwgPosition)
    (setq PtbTemp (PanPtbXYZ (list PT10 PT11) PT1 (nth index WPJdwgPosition))
         WPJColumn2 (ssget "C" (car PtbTemp) (cadr PtbTemp)  '((0 . "text") (8 . "22000,28000")))
	)
    (command ".copy" WPJColumn2 "" (nth index WPJdwgPosition) PT1)
    (command ".line" (car PtbTemp) (cadr PtbTemp) "")
    (setq index (1+ index))
  );end repeat,把后面要归并的柱配筋文字移动到首层位置了;
  (setq PickBoxWuCHa_Column (/ (mai_dxf 40 (entget (ssname WPJColumn 0))) 2);由配筋文字大小得到选择框误差大小;
  ;一,处理柱配筋值;
        N (sslength WPJColumn)
        index 0
  )
  (repeat N
    (setq WpjTextEnt (entget (ssname WPJColumn index))
          index (1+ index)
          WpjText (mai_dxf 1 WpjTextEnt)
		  WpjTextHeight (mai_dxf 40 WpjTextEnt)
		  WpjTextAngle (mai_dxf 50 WpjTextEnt)
          Pt1 (mai_dxf 10 WpjTextEnt)
          Pt2 (mai_dxf 11 WpjTextEnt)
          Pt3 (polar Pt2 (+ WpjTextAngle (/ pi 2)) WpjTextHeight)
          Pt4 (polar Pt1 (+ WpjTextAngle (/ pi 2)) WpjTextHeight)
	)
    (cond ((wcmatch WpjText "G*-*");箍筋;
           (setq PickBoxWuCHa_Beam
		         PickBoxWuCHa_Column
                 WPJColumn2 (ssget "cp" (PickOutRec_Beam Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "22000") (1 . "G*-*")));取得其它层箍筋;
		   )
           (if WPJColumn2 (MAXWpjAs_Beam "AsG" WpjTextEnt WPJColumn2));此处柱箍筋分离方法同梁筋;
           (setq WPJColumn2 nil)
	      )
          ((wcmatch WpjText "*.*");角筋以及核心区抗剪箍筋;
           (setq PickBoxWuCHa_Beam
		         PickBoxWuCHa_Column
                 WPJColumn2 (ssget "cp" (PickOutRec_Beam Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "22000") (1 . "*.*")));角筋以及核心区抗剪箍筋;
		   )
           (if WPJColumn2 (MAXWpjAs_Clu WpjTextEnt WPJColumn2))
           (setq WPJColumn2 nil)
	      )
          (T      ;柱纵筋;
           (setq WPJColumn2 (ssget "cp" (PickOutRec_Column Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "22000"))))
           (if WPJColumn2 (MAXWpjAs_Clu_ZHJ WpjTextEnt WPJColumn2))
           (setq WPJColumn2 nil)
	      )
	)
  )
  ;二,处理柱轴压比;
  (setq N (sslength WPJZHouYaBi) index 0)
  (repeat N
    (setq WpjTextEnt (entget (ssname WPJZHouYaBi index))
          index (1+ index)
          WpjText (mai_dxf 1 WpjTextEnt)
		  WpjTextHeight (mai_dxf 40 WpjTextEnt)
		  WpjTextAngle (mai_dxf 50 WpjTextEnt)
          Pt1 (mai_dxf 10 WpjTextEnt)
          Pt2 (mai_dxf 11 WpjTextEnt)
          Pt3 (polar Pt2 (+ WpjTextAngle (/ pi 2)) WpjTextHeight)
          Pt4 (polar Pt1 (+ WpjTextAngle (/ pi 2)) WpjTextHeight)
          WPJZHouYaBi2 (ssget "cp" (PickOutRec_Beam Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "28000")))
	)
    (if WPJZHouYaBi2 (MAXWpjAs_ZHYB WpjTextEnt WPJZHouYaBi2))
  )
  ;(clos)
  ;(undo_end)
  (princ)
  )

;PKPM墙配筋图归并;
(defun c:QGB() (PKPMWall))

(defun PKPMWall ( / PickBoxWuCHa_Wall GuiBingN WPJdwgPosition PT1 PT10 PT11 PT12 PT13 TempPT
                   WPJWall WPJWall2 PtbTemp index N WpjTextEnt WpjText WpjTextHeight WpjTextAngle
				)
  ;(svos)
  ;(setvar "cmdecho" 0)
  ;(undo_begin)
  (princ "\nPKPM墙配筋图归并程序，由TITAN编写.QQ:357574033,EMail:STONEK@21CN.COM")
  (setq GuiBingN (getint "\n请输入要归并的层数:")
        index 1
        WPJdwgPosition '()
        GuiBingN (if GuiBingN (1- GuiBingN) 0)
        PT1 (getpoint "\n请输入首层归并图纸参考坐标特征点:")
  )
  (repeat GuiBingN
      (setq index (+ index 1)
            TempPT (getpoint (strcat "\n请输入第" (itoa index) "层配筋计算简图定位特征点:"))
            WPJdwgPosition (append WPJdwgPosition (list TempPT))
  );得到其余层定位特征点;
  (alert "\n层定位已完成,下面输入两点供框选首层配筋图纸.")
  (setq PT10 (getpoint "\n下面输入两点供框选首层配筋图纸,请输入第一点:")
        PT11 (getcorner pt10 "\n请输入第二点:")
        WPJWall (ssget "C" PT10 PT11 '((0 . "text") (8 . "24000")))
        index 0
  )
  (if (not GBColor);归并颜色;
      (setq Oldcecolor (getvar "cecolor")
            GBColor (acad_colordlg 7)
	  )
  )
  (mai_create_layer "WPJ_Wall" GBcolor)
  (command ".chprop" WPJWall "" "layer" "WPJ_Wall" "")
  (setvar "cecolor" Oldcecolor)
  (command ".zoom" "e")
  (repeat (length WPJdwgPosition)
    (setq PtbTemp (PanPtbXYZ (list PT10 PT11) PT1 (nth index WPJdwgPosition))
          WPJWall2 (ssget "C" (car PtbTemp) (cadr PtbTemp)  '((0 . "text") (8 . "24000")))
    )
    (command ".copy" WPJWall2 "" (nth index WPJdwgPosition) PT1)
    (command ".line" (car PtbTemp) (cadr PtbTemp) "")
    (setq index (1+ index))
  );end repeat,把后面要归并的柱配筋文字移动到首层位置了;
  (setq PickBoxWuCHa_Wall (/ (mai_dxf 40 (entget (ssname WPJWall 0))) 2);由配筋文字大小得到选择框误差大小;
        N (sslength WPJWall)
		index 0
  )
  (repeat N
    (setq WpjTextEnt (entget (ssname WPJWall index))
          index (1+ index)
          WpjText (mai_dxf 1 WpjTextEnt)
		  WpjTextHeight (mai_dxf 40 WpjTextEnt)
		  WpjTextAngle (mai_dxf 50 WpjTextEnt)
          Pt1 (mai_dxf 10 WpjTextEnt)
          Pt2 (mai_dxf 11 WpjTextEnt)
          Pt3 (polar Pt2 (+ WpjTextAngle (/ pi 2)) WpjTextHeight)
          Pt4 (polar Pt1 (+ WpjTextAngle (/ pi 2)) WpjTextHeight)
	)
    (cond ((wcmatch WpjText "G*");连梁LL箍筋;
           (setq WPJWallBeam2 (ssget "cp" (PickOutRec_WaLL Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "24000") (1 . "G*"))))
           (if WPJWallBeam2 ;如果有选择到就在选出max值赋予WpjTextEnt;
              (MAXWpjAs_Beam "AsG" WpjTextEnt WPJWallBeam2)
		   )
		  )
          ((wcmatch WpjText "*-*-*");梁面筋或底筋;
           (setq WPJWallBeam2 (ssget "cp" (PickOutRec_Wall Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "24000") (1 . "*-*-*"))))
           (if WPJWallBeam2 ;如果有选择到就在选出max值赋予WpjTextEnt;
               (MAXWpjAs_Beam "As" WpjTextEnt WPJWallBeam2)
		   )
		  )
          ((wcmatch WpjText "H*");墙H筋;
           (setq WPJWall2 (ssget "cp" (PickOutRec_Wall Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "24000") (1 . "H*"))))
           (if WPJWall2 ;如果有选择到就在选出max值赋予WpjTextEnt;
              (MAXWpjAs_Wall "AsH" WpjTextEnt WPJWall2)
		   )
		  )
          (T
           (setq WPJWall2 (ssget "cp" (PickOutRec_Wall Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "24000") (1 . "#*"))))
           (if WPJWall2 (MAXWpjAs_Wall "AsV" WpjTextEnt WPJWall2))
		  )
	)
  )
  ;(clos)
  ;(undo_end)
  (princ)
  )
;文件2/3

;PKPM墙边缘构件图归并;
(defun c:BYGJGB() (PKPMWallEdge))

(defun PKPMWallEdge ( / PickBoxWuCHa_Wall GuiBingN WPJdwgPosition PT1 PT10 PT11 PT12 PT13 TempPT
                       WPJWall WPJWall2 PtbTemp index N WpjTextEnt WpjText WpjTextHeight WpjTextAngle
					)
  ;(svos)
  ;(setvar "cmdecho" 0)
  ;(undo_begin)
  (princ "\nPKPM墙边缘构件图归并程序，由TITAN编写.QQ:357574033,EMail:STONEK@21CN.COM")
  (setq GuiBingN (getint "\n请输入要归并的层数:")
        index 1
        ;WPJdwgPosition '()
        GuiBingN (if GuiBingN (1- GuiBingN) 0)
        PT1 (getpoint "\n请输入首层归并图纸参考坐标特征点:")
  )
  (repeat GuiBingN
     (setq index (+ index 1)
           TempPT (getpoint (strcat "\n请输入第" (itoa index) "层边缘构件计算简图定位特征点:"))
           WPJdwgPosition (append WPJdwgPosition (list TempPT))
	 )
  );得到其余层定位特征点;
  (alert "\n层定位已完成,下面输入两点供框选首层边缘构件图纸.")
  (setq PT10 (getpoint "\n下面输入两点供框选首层边缘构件图纸,请输入第一点:")
        PT11 (getcorner pt10 "\n请输入第二点:")
        WPJWall (ssget "C" PT10 PT11 '((0 . "text") (8 . "7")))
        index 0
  )
  (if (not GBColor);归并颜色;
      (setq Oldcecolor (getvar "cecolor")
            GBColor (acad_colordlg 7)
	  )
  )
  (mai_create_layer "WPJ_WallEdge" GBcolor)
  (setvar "cecolor" Oldcecolor)
  (command ".chprop" WPJWall "" "layer" "WPJ_WallEdge" "")
  (command ".zoom" "e")
  (repeat (length WPJdwgPosition)
    (setq PtbTemp (PanPtbXYZ (list PT10 PT11) PT1 (nth index WPJdwgPosition))
          WPJWall2 (ssget "C" (car PtbTemp) (cadr PtbTemp)  '((0 . "text") (8 . "7")))
    )
    (command ".copy" WPJWall2 "" (nth index WPJdwgPosition) PT1)
    (command ".line" (car PtbTemp) (cadr PtbTemp) "")
    (setq index (1+ index))
  );end repeat,把后面要归并的柱配筋文字移动到首层位置了;
  (setq PickBoxWuCHa_Wall (/ (mai_dxf 40 (entget (ssname WPJWall 0))) 2);由配筋文字大小得到选择框误差大小;
        N (sslength WPJWall)
		index 0
  )
  (repeat N
    (setq WpjTextEnt (entget (ssname WPJWall index))
          index (1+ index)
          WpjText (mai_dxf 1 WpjTextEnt)
		  WpjTextHeight (mai_dxf 40 WpjTextEnt)
		  WpjTextAngle (mai_dxf 50 WpjTextEnt)
          Pt1 (mai_dxf 10 WpjTextEnt)
          Pt2 (mai_dxf 11 WpjTextEnt)
          Pt3 (polar Pt2 (+ WpjTextAngle (/ pi 2)) WpjTextHeight)
          Pt4 (polar Pt1 (+ WpjTextAngle (/ pi 2)) WpjTextHeight)
	)
    (cond ((wcmatch WpjText "Psv*");边缘构件箍筋;
           (setq WPJWallBeam2 (ssget "cp" (PickOutRec_WaLL Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "7") (1 . "Psv*"))))
           (if WPJWallBeam2 ;如果有选择到就在选出max值赋予WpjTextEnt;
               (MAXWpjAs_WallEdge "Psv" WpjTextEnt WPJWallBeam2)
		   )
		  )
          ((wcmatch WpjText "As*");主筋面积;
           (setq WPJWallBeam2 (ssget "cp" (PickOutRec_Wall Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "7") (1 . "As*"))))
           (if WPJWallBeam2 ;如果有选择到就在选出max值赋予WpjTextEnt;
               (MAXWpjAs_WallEdge "As" WpjTextEnt WPJWallBeam2)
		   )
		  )
          ((wcmatch WpjText "Ls*");Ls长度;
           (setq WPJWall2 (ssget "cp" (PickOutRec_Wall Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "7") (1 . "Ls*"))))
           (if WPJWall2 ;如果有选择到就在选出max值赋予WpjTextEnt;
               (MAXWpjAs_Wall "Ls" WpjTextEnt WPJWall2)
		   )
		  )
          ((wcmatch WpjText "Lc*");Lc长度;
           (setq WPJWall2 (ssget "cp" (PickOutRec_Wall Pt1 Pt2 pt3 pt4) '((0 . "text") (8 . "7") (1 . "Lc*"))))
           (if WPJWall2 (MAXWpjAs_Wall "Lc" WpjTextEnt WPJWall2))
		  )
    )
  )
  ;(clos)
  ;(undo_end)
  (princ)
  )

(defun PickOutRec_Beam ( pt10 pt11 pt12 pt13 / pt1 pt2 pt3 pt4 ang1 ang2 ang3 ang4);梁筋搜索选择框;
  (setq ang1 (angle pt10 pt11)
        ang2 (angle pt11 pt12)
        ang3 (angle pt11 pt10)
		ang4 (angle pt12 pt11)
        pt1 (polar (polar pt10 ang3 (* 2 PickBoxWuCHa_Beam)) ang4 PickBoxWuCHa_Beam)
        pt2 (polar (polar pt11 ang1 (* 2 PickBoxWuCHa_Beam)) ang4 PickBoxWuCHa_Beam)
        pt3 (polar (polar pt12 ang1 (* 2 PickBoxWuCHa_Beam)) ang2 PickBoxWuCHa_Beam)
        pt4 (polar (polar pt13 ang3 (* 2 PickBoxWuCHa_Beam)) ang2 PickBoxWuCHa_Beam)
  )
  (list pt1 pt2 pt3 pt4)
)

(defun PickOutRec_Column ( pt10 pt11 pt12 pt13 / pt1 pt2 pt3 pt4 ang1 ang2 ang3 ang4);柱筋搜索选择框;
  (setq ang1 (angle pt10 pt11)
        ang2 (angle pt11 pt12)
        ang3 (angle pt11 pt10)
		ang4 (angle pt12 pt11)
        pt1 (polar (polar pt10 ang3 PickBoxWuCHa_Column) ang4 PickBoxWuCHa_Column)
        pt2 (polar (polar pt11 ang1 PickBoxWuCHa_Column) ang4 PickBoxWuCHa_Column)
        pt3 (polar (polar pt12 ang1 PickBoxWuCHa_Column) ang2 PickBoxWuCHa_Column)
        pt4 (polar (polar pt13 ang3 PickBoxWuCHa_Column) ang2 PickBoxWuCHa_Column)
  )
  (list pt1 pt2 pt3 pt4)
)

(defun PickOutRec_WaLL (pt10 pt11 pt12 pt13 / p1 p2 p3 p4 ang1 ang2 ang3 ang4);墙筋搜索选择框;
  (setq ang1 (angle pt10 pt11)
        ang2 (angle pt11 pt12)
        ang3 (angle pt11 pt10)
		ang4 (angle pt12 pt11)
        pt1 (polar (polar pt10 ang3 (* 2 PickBoxWuCHa_WaLL)) ang4 PickBoxWuCHa_WaLL)
        pt2 (polar (polar pt11 ang1 (* 2 PickBoxWuCHa_WaLL)) ang4 PickBoxWuCHa_WaLL)
        pt3 (polar (polar pt12 ang1 (* 2 PickBoxWuCHa_WaLL)) ang2 PickBoxWuCHa_WaLL)
        pt4 (polar (polar pt13 ang3 (* 2 PickBoxWuCHa_WaLL)) ang2 PickBoxWuCHa_WaLL)
  )
  (list pt1 pt2 pt3 pt4)
)
 
(defun MAXWpjAs_Beam ( WPJType WpjTextEnt WPJBeam2 / WpjText N1 index AsLeftList AsMiddList AsRightList As
                                                     AsLeft AsMidd AsRight
				     );WPJType为AsG,AsT,As;
  (setq WPJBeam2 (FilterOtherAngleEnt WpjTextEnt WPJBeam2);过滤掉不同角度的实体;
        WpjText (mai_dxf 1 WpjTextEnt)
		N1 (sslength WPJBeam2)
		index 0
  )
  (cond ((= WPJType "AsG")
         (setq WpjText (separateAsv&Ast WpjText)
               AsLeftList (list (car WpjText))
               AsRightList (list (cadr WpjText))
		 )
         (repeat N1
            (setq WpjText2 (mai_dxf 1 (entget (ssname WPJBeam2 index)))
                  WpjText2 (separateAsv&Ast WpjText2)
                  AsLeftList (append AsLeftList (list (car WpjText2)))
                  AsRightList (append AsRightList (list (cadr WpjText2)))
                  index (1+ index)
		    )
	     )
         (setq AsLeft (apply 'max AsLeftList)
               AsRight (apply 'max AsRightList)
               As (strcat "G" (Real2String AsLeft 1) "-" (Real2String AsRight 1))
               WpjTextEnt (subst (cons 1 As) (assoc 1 WpjTextEnt) WpjTextEnt)
		 )
         (entmod WpjTextEnt)
	    )
        ((= WPJType "AsT")
         (setq WpjText (separateAsv&Ast WpjText)
               AsLeftList (list (car WpjText))
               AsRightList (list (cadr WpjText))
	     )
        (repeat N1
          (setq WpjText2 (mai_dxf 1 (entget (ssname WPJBeam2 index)))
                WpjText2 (separateAsv&Ast WpjText2)
                AsLeftList (append AsLeftList (list(car WpjText2)))
                AsRightList (append AsRightList (list(cadr WpjText2)))
                index (1+ index)
	      )
		)
        (setq AsLeft (apply 'max AsLeftList)
              AsRight (apply 'max AsRightList)
              As (strcat "VT" (Real2String AsLeft 0) "-" (Real2String AsRight 1))
              WpjTextEnt (subst(cons 1 As) (assoc 1 WpjTextEnt)  WpjTextEnt)
		)
        (entmod WpjTextEnt)
	   )
       ((= WPJType "As")
        (setq ;WpjText (separateAsu&Asd WpjText);分离梁面筋和底筋;
		      WpjText (mapcar 'atoi (mai_str2lst WpjText "-"))
              AsLeftList (list(car WpjText))
              AsMiddList (list(cadr WpjText))
              AsRightList (list(caddr WpjText))
	    )
        (repeat N1
          (setq WpjText2 (mai_dxf 1 (entget (ssname WPJBeam2 index)))
                ;WpjText2 (separateAsu&Asd WpjText2);分离梁面筋和底筋;
		        WpjText2 (mapcar 'atoi (mai_str2lst WpjText2 "-"))
                AsLeftList (append AsLeftList (list(car WpjText2)))
                AsMiddList (append AsMiddList (list(cadr WpjText2)))
                AsRightList (append AsRightList (list(caddr WpjText2)))
                index (1+ index)
		  )
	    )
        (setq AsLeft (apply 'max AsLeftList)
              AsMidd (apply 'max AsMiddList)
              AsRight (apply 'max AsRightList)
              As (strcat (itoa AsLeft) "-" (itoa AsMidd) "-" (itoa AsRight))
              WpjTextEnt (subst (cons 1 As) (assoc 1 WpjTextEnt) WpjTextEnt)
	    )
        (entmod WpjTextEnt)
	   )
  )
  (command ".erase" WPJBeam2 "")
 )

(defun MAXWpjAs_Clu ( WpjTextEnt WPJColumn2 / WpjText ColumnAstList N1 index  WpjText2 As)
  (setq WPJColumn2 (FilterOtherAngleEnt WpjTextEnt WPJColumn2) ;过滤掉不同角度的实体;
        WpjText (mai_dxf 1 WpjTextEnt)
        ColumnAstList (list WpjText)
        N1 (sslength WPJColumn2)
        index 0
  )
  (repeat N1
    (setq WpjText2 (mai_dxf 1 (entget (ssname WPJColumn2 index)))
          ColumnAstList (append ColumnAstList (list WpjText2))
          index (1+ index)
    )
  )
  (setq As (apply 'max (mapcar '(lambda (x) (atof x)) ColumnAstList))
        As (Real2String As 1)
        WpjTextEnt (subst (cons 1 As) (assoc 1 WpjTextEnt) WpjTextEnt)
  )
  (entmod WpjTextEnt)
  (command ".erase" WPJColumn2 "")
)

(defun MAXWpjAs_Clu_ZHJ ( WpjTextEnt WPJColumn2 / WpjText ColumnAstList N1 index  WpjText2 As)
  (setq WPJColumn2 (FilterOtherAngleEnt WpjTextEnt WPJColumn2);过滤掉不同角度的实体;
        WPJColumn2 (FilterDoteEnt WPJColumn2);在WPJColumn2过滤掉可能含"."的实体;
        WpjText (mai_dxf 1 WpjTextEnt)
        ColumnAstList (list WpjText)
        N1 (sslength WPJColumn2)
        index 0
  )
  (repeat N1
    (setq WpjText2 (mai_dxf 1 (entget (ssname WPJColumn2 index)))
          ColumnAstList (append ColumnAstList (list WpjText2))
          index (1+ index)
	)
  )
  (setq As (apply 'max (mapcar '(lambda (x) (atof x)) ColumnAstList))
        As (Real2String As 0) ;与上面的function不同的只是小数位数差别;
        WpjTextEnt (subst (cons 1 As) (assoc 1 WpjTextEnt) WpjTextEnt)
  )
  (entmod WpjTextEnt)
  (command ".erase" WPJColumn2 "")
  )

(defun MAXWpjAs_ZHYB ( WpjTextEnt WPJZHouYaBi2 / WpjText ZHYBList N1 index  WpjText2 As)
  (setq WPJZHouYaBi2 (FilterOtherAngleEnt WpjTextEnt WPJZHouYaBi2) ;过滤掉不同角度的实体;
        WpjText (mai_dxf 1 WpjTextEnt)
        WpjText (substr WpjText 2 (- (strlen WpjText) 2))
        ZHYBList (list WpjText)
        N1 (sslength WPJZHouYaBi2)
        index 0
  )
  (repeat N1
    (setq WpjText2 (mai_dxf 1 (entget (ssname WPJZHouYaBi2 index)))
          WpjText2 (substr WpjText2 2 (- (strlen WpjText2) 2))
          ZHYBList (append ZHYBList (list WpjText2))
          index (1+ index)
    )
  )
  (setq As (apply 'max (mapcar '(lambda (x) (atof x)) ZHYBList))
        As (Real2String As 2)
        As (strcat "(" As ")")
        WpjTextEnt (subst(cons 1 As) (assoc 1 WpjTextEnt)  WpjTextEnt)
  )
  (entmod WpjTextEnt)
  (command ".erase" WPJZHouYaBi2 "")
  )
;文件3/3

(defun MAXWpjAs_Wall(WPJType WpjTextEnt WPJWall2 / WpjText N1 index  WpjText2 AsHList AsVList AsH AsV)
  (setq WPJWall2 (FilterOtherAngleEnt WpjTextEnt WPJWall2);过滤掉不同角度的实体;
        WpjText (mai_dxf 1 WpjTextEnt)
        N1 (sslength WPJWall2)
        index 0
  )
  (cond ((= WPJType "AsH")
         (setq WpjText (substr WpjText 2)
               AsHList (list WpjText)
		 )
         (repeat N1
           (setq WpjText2 (mai_dxf 1 (entget (ssname WPJWall2 index)))
                 WpjText2 (substr WpjText2 2)
                 AsHList (append AsHList (list WpjText2))
                 index (1+ index)
		   )
	     )
         (setq AsH (car (vl-sort AsHList '>))
               AsH (strcat "H" AsH)
               WpjTextEnt (subst(cons 1 AsH) (assoc 1 WpjTextEnt)  WpjTextEnt)
		 )
         (entmod WpjTextEnt)
	    )
        ((= WPJType "AsV")
         (setq AsVList (list WpjText))
         (repeat N1
            (setq WpjText2 (mai_dxf 1 (entget (ssname WPJWall2 index)))
                  AsVList (append AsVList (list WpjText2))
                  index (1+ index)
			)
	     )
         (setq AsV (car (vl-sort AsVList '>))
               WpjTextEnt (subst(cons 1 AsV) (assoc 1 WpjTextEnt)  WpjTextEnt)
		 )
         (entmod WpjTextEnt)
        )
   )
   (command ".erase" WPJWall2 "")
  )

(defun MAXWpjAs_WallEdge ( WPJType WpjTextEnt WPJWall2 / WpjText N1 index  WpjText2 PsvList Psv AsList1 AsList2 As1 As2 As
                                                         LsList1 LsList2 Ls1 Ls2 Ls LcList Lc
						 )
  (setq WPJWall2 (FilterOtherAngleEnt WpjTextEnt WPJWall2);过滤掉不同角度的实体;
        WpjText (mai_dxf 1 WpjTextEnt)
        N1 (sslength WPJWall2)
        index 0
  )
  (cond ((= WPJType "Psv")
         (setq WpjText (substr WpjText 4 4)
               PsvList (list WpjText)
	     )
         (repeat N1
           (setq WpjText2 (mai_dxf 1 (entget (ssname WPJWall2 index)))
                ;WpjText2 (distof (substr WpjText2 4 7) 2);取出Psv1.57%的4~7位;
                 WpjText2 (substr WpjText2 4 4)
                 PsvList (append PsvList (list WpjText2))
                 index (1+ index)
		   )
		 )
         (setq Psv (car (vl-sort PsvList '>))
               Psv (strcat "Psv" Psv "%")
               WpjTextEnt (subst (cons 1 Psv) (assoc 1 WpjTextEnt)  WpjTextEnt))
		 )
         (entmod WpjTextEnt)
	    )
        ((= WPJType "As")
         (if (wcmatch WPJType "*(*%)") ;类似As1400(1.12%);
             (progn
                (setq AsList1 (list (substr WpjText 3 (- (vl-string-position (ascii "(") WpjText) 2)))
                      AsList2 (list (substr WpjText (+ 2 (vl-string-position (ascii "(") WpjText)) 4))
			    )
                (repeat N1
                  (setq WpjText2 (mai_dxf 1 (entget (ssname WPJWall2 index)))
                        AsList1 (append AsList1 (list (substr WpjText2 3 (- (vl-string-position (ascii "(") WpjText2) 2))))
                        AsList2 (append AsList2 (list (substr WpjText2 (+ 2 (vl-string-position (ascii "(") WpjText2)) 4)))
                        index (1+ index)
				  )
				)
                (setq As1 (car (vl-sort AsList1 '>))
                      As2 (car (vl-sort AsList2 '>))
                      As (strcat "As" As1 "(" As2 "%)")
			    )
             )
             (progn ;类似As1400;
                (setq AsList1 (list (substr WpjText 3)))
                (repeat N1
                   (setq WpjText2 (mai_dxf 1 (entget (ssname WPJWall2 index)))
                         AsList1 (append AsList1 (list (substr WpjText2 3 (- (vl-string-position (ascii "(") WpjText2) 2))))
                         index (1+ index)
				   )
				)
                (setq As1 (car (vl-sort AsList1 '>))
                      As (strcat "As" As1)
				)
             )
         );end if;
         (setq WpjTextEnt (subst(cons 1 As) (assoc 1 WpjTextEnt)  WpjTextEnt))
         (entmod WpjTextEnt)
        )
        ((= WPJType "Ls")
         (if (wcmatch WPJType "*/Lt*")
             (progn ;类似Ls350/Lt350;
              (setq LsList1 (list (substr WpjText 3 (- (vl-string-position (ascii "/") WpjText) 1)))
                    LsList2 (list (substr WpjText (+ 2 (vl-string-position (ascii "t") WpjText))))
			  )
              (repeat N1
                 (setq WpjText2 (mai_dxf 1 (entget (ssname WPJWall2 index)))
                       LsList1 (append LsList1 (list (substr WpjText2 3 (- (vl-string-position (ascii "/") WpjText2) 1))))
                       LsList2 (append LsList2 (list (substr WpjText2 (+ 2 (vl-string-position (ascii "t") WpjText2)))))
                       index (1+ index)
				 )
			  )
              (setq Ls1 (car (vl-sort LsList1 '>))
                    Ls2 (car (vl-sort LsList2 '>))
                    Ls (strcat "Ls" Ls1 "/Lt" Ls2)
			  )
             )
             (progn ;类似Ls350;
               (setq LsList1 (list (substr WpjText 3)))
               (repeat N1
                   (setq WpjText2 (mai_dxf 1 (entget (ssname WPJWall2 index)))
                         LsList1 (append LsList1 (list (substr WpjText2 3)))
                         index (1+ index)
				   )
			   )
               (setq Ls1 (car (vl-sort LsList1 '>))
                     Ls (strcat "Ls" Ls1)
			   )
             )
         );end if;
         (setq WpjTextEnt (subst (cons 1 Ls) (assoc 1 WpjTextEnt) WpjTextEnt))
         (entmod WpjTextEnt)
        )
        ((= WPJType "Lc")
         (setq LcList (list (substr WpjText 3)))
         (repeat N1
           (setq WpjText2 (mai_dxf 1 (entget (ssname WPJWall2 index)))
                 LcList (append AsVList (list (substr WpjText2 3)))
                 index (1+ index)
		   )
		 )
         (setq Lc (car (vl-sort LcList '>))
               Lc (strcat "Lc" Lc)
               WpjTextEnt (subst (cons 1 Lc) (assoc 1 WpjTextEnt) WpjTextEnt)
		 )
         (entmod WpjTextEnt)
        )
  )
  (command ".erase" WPJWall2 "")
 )

 ;|
(defun separateAsu&Asd ( str / ChaPosition1 ChaPosition2 AsLeft AsMidd AsRight);分离梁面筋和底筋;
  (setq ChaPosition1 (VL-STRING-position (ascii "-") str 0)
        ChaPosition2 (VL-STRING-position (ascii "-") str 0 t)
        AsLeft (substr str 1 ChaPosition1)
       AsMidd (substr str (+ ChaPosition1 2) (- ChaPosition2 ChaPosition1 1))
        AsRight (substr str (+ ChaPosition2 2) (- (strlen str) ChaPosition2))
  )
  (mapcar 'atoi (list AsLeft AsMidd AsRight))
)
;|;

(defun separateAsv&Ast(str / n s1 cha);分离梁箍筋和扭筋;
  (setq AsLeft  (cond ((wcmatch str "G*") 2)
                      ((wcmatch str "VT*") 3)
                )
        str (substr str AsLeft)
        ChaPosition1 (VL-STRING-position (ascii "-") str 0)
        AsLeft (substr str 1 ChaPosition1)
        AsRight (substr str (+ ChaPosition1 2) )
  )
  (list (atof AsLeft) (atof AsRight))
)

(defun FilterOtherAngleEnt (WpjTextEnt WPJColumn2 / Ang1 Ang2 N index WPJColumn3) ;在WPJColumn2过滤掉与WpjTextEnt的文字转角不同的实体;
  (setq Ang1 (mai_dxf 50 WpjTextEnt)
        N (sslength WPJColumn2)
		index 0
		WPJColumn3 (ssadd)
  )
  (repeat N
    (setq tmp (ssname WPJColumn2 index)
	      Ang2 (mai_dxf 50 tmp)
          index (1+ index)
	)
    (if (mai_equal_angle Ang1 Ang2)
        (setq WPJColumn3 (ssadd tmp WPJColumn3))
	)
  )
  (setq WPJColumn2 WPJColumn3)
)

(defun FilterDoteEnt ( WPJColumn2 / text N index WPJColumn3) ;在WPJColumn2过滤掉可能含"."号的实体;
  (setq N (sslength WPJColumn2) index 0 WPJColumn3 (ssadd))
  (repeat N
    (setq text (mai_dxf 1 (entget (ssname WPJColumn2 index))))
    (if (wcmatch text "*.*") ;含"."号的实体;
        (setq WPJColumn2 (ssdel (ssname WPJColumn2 index) WPJColumn2))
    )
    (setq index (1+ index))
  )
    ;(setq WPJColumn2 WPJColumn3)
    WPJColumn2
  )

(defun PanPtbXYZ ( Ptb SourcePT TargetPT / PanXYZ );求在SourcePT下点表Ptb平移到TargetPT后得到新的坐标;
  (setq PanXYZ (mapcar '- TargetPT SourcePT))
  (mapcar '(lambda (x) (mapcar '+ x PanXYZ)) Ptb)
)

(defun Real2String ( RealNum XiaoShuWeiShu / x y z);实数以及小数位数;
  (cond ((= XiaoShuWeiShu 0)
         (itoa (fix ((if (> RealNum 0) + -) RealNum 0.5)))
		)
        ((>= XiaoShuWeiShu 1)
		 (setq x (fix RealNum)
               y (fix (+ 0.5 (* (abs (- RealNum x)) (expt 10 XiaoShuWeiShu))))
               x (itoa x)
               y (itoa y)
               z (strcat x "." y)
		 )
		)
        (t (princ "没有定义小数位数为负数的情况!"))
  )
)
