www.pudn.com > CADtool.rar > PS_jtj.lsp, change:2009-04-10,size:8943b


;;;------------------------------------------------------------- 
;;; 统计各类型的井数量 
;| 处理流程: 
1.选择圆 
2.对每个圆: 
 a.查询井类型 
 b.选择与圆相关的所有管道 
 c.检测最大管径值 
 d.对结果表中对应类型的井个数增加1 
3.对结果表进行排序 
4.输出数量表 
|; 
 
(defun C:PS_jtj (/                  keyWord            ssCircles          strCircleEName     listResult 
                 listJinXData       strJinLabel        floatMaxGuanJin    intJinUndefinedNumber 
                 intJinWithNoPipeNumber                listOriginal       strTemp           k 
                ) 
;;;------------------------------------------------------------- 
;;;检查与指定井连接的管道的最大管径,无连接管时,返回值为0 
 (defun GetMaxGuanJin (strCircleEName      /                   floatCircleRadius   floatCircleRadiusBiger 
                       ptCenter            angKPoint           listPointsFilter    k 
                       ssGuanDao           strGuanDaoEName     listGuanDaoXData    floatGuanJin 
                       floatMaxGuanJin listObjectFilter 
                      ) 
  (setq floatCircleR (cdr (assoc 40 (entget strCircleEName)))) 
  (setq floatCircleRadiusBiger (* 1.1 floatCircleR) 
        ptCenter               (cdr (assoc 10 (entget strCircleEName))) 
	    listObjectFilter       (list (cons 0  "LINE,POLYLINE,LWPOLYLINE,ARC")  (list -3 (list "PS_GD")))    
        k                      1 
  ) 
 
  (setq listPointsFilter (list (polar ptCenter 0 floatCircleRadiusBiger))) 
  (repeat 7 
   (setq angKPoint (* k (/ pi 4))) 
   (setq listPointsFilter (append listPointsFilter 
                                  (list (polar ptCenter angKPoint floatCircleRadiusBiger)) 
                          ) 
   ) 
   (setq k (1+ k)) 
  )       ;生成选择集的过滤点表 
 
  (setq ssGuanDao (ssget "_CP" listPointsFilter listObjectFilter ) ) 
 
  (setq floatMaxGuanJin 0 
        k -1 
  ) 
 
  (repeat (sslength ssGuanDao) ; 循环与所选择的对象数量相等的次数 
   (setq strGuanDaoEName (ssname ssGuanDao (setq k (1+ k)))) ; obname,取得第k个对象名 
 
;;;取得管道管径 
;;;("PS_GD" (1000 . "D") (1040 . 800.0))) 
   (setq listGuanDaoXData (cadr (assoc -3 (entget strGuanDaoEName '("PS_GD"))))) 
   (if listGuanDaoXData 
    (progn 
     (setq floatGuanJin (cdr (caddr listGuanDaoXData))) ;有管道标记时处理 
     (if (> floatGuanJin floatMaxGuanJin) 
      (setq floatMaxGuanJin floatGuanJin) 
     ) 
    ) 
   ) 
  ) 
 
  floatMaxGuanJin 
 ) 
;;;------------------------------------------------------------- 
;;;把listOriginal ((  井类型-最大管径 , 1   )  ) 表处理后成一个结果表和一个未处理的新表,并把listOriginal设置为新表 
 (defun SortList (/ NewList i ListLength strJinType intJinNumber) 
  (setq strJinType (car (nth 0 listOriginal))) 
  (setq intJinNumber (cadr (nth 0 listOriginal))) 
  (setq NewList nil) 
  (setq ListLength (length listOriginal)) 
  (if (> ListLength 1) 
   (progn 
    (setq i 1) 
    (while (< i ListLength) 
     (if (= strJinType (car (nth i listOriginal))) 
      (setq intJinNumber (+ intJinNumber (cadr (nth i listOriginal)))) 
 
      (setq NewList (append NewList (list (nth i listOriginal)))) 
     ) 
     ;;如果表的当前元素管径与第一顶的相同,则计算总管长;否则,把当前元素放到新表中 
 
     (setq i (1+ i)) 
    ) 
   ) 
  ) 
  (setq listResult (append listResult (list (list strJinType intJinNumber)))) 
  ;;把本次计算结果放到结果表末尾 
 
  (setq listOriginal NewList) 
 ) 
;;;------------------------------------------------------------------------ 
;;;对结果表进行排序,并返回排序后的结果表 
 (defun SortResultList (listOriginal / MidList listSorted i k nt NkMidList NkOriginalList) 
  (setq nt (length listOriginal)) 
  (if (> nt 1) 
   (progn 
    (setq MidList nil 
          listSorted nil 
          k 0 
    ) 
 
    (repeat nt 
     (setq MidList (append MidList 
                           (list (car (nth k listOriginal))) 
                   ) 
     ) 
     (setq k (1+ k)) 
    )     ;生成管径字符表 
 
    (setq MidList (acad_strlsort MidList)) 
;;;对管径字符串表进行排序 
 
    (if (not MidList) 
     (setq listSorted listOriginal) 
;;;如果对管径字符串表排序不成功,返回原始表 
 
     (progn 
      (setq k 0) 
      (repeat nt 
       (setq i              0 
             NkMidList      (nth k MidList) 
             NkOriginalList (nth 0 listOriginal) 
       ) 
 
       (while (/= NkMidList (car NkOriginalList)) 
        (setq i (1+ i)) 
        (setq NkOriginalList (nth i listOriginal)) 
       ) 
       (setq listSorted (append listSorted (list NkOriginalList))) 
       (setq k (1+ k)) 
      ) 
     ) 
    ) 
 
   ) 
 
   (setq listSorted listOriginal) 
  )       ;如果表元素个数大于1,就对表进行排序 
 
  listSorted 
 ) 
;;;------------------------------------------------------------------------ 
;;;打印结果表 
 (defun PrintList (/ i ListLength strJinType intJinNumber sJinNumber pt pt1 pt2 x y x1 y1 x2) 
  (setq pt (getpoint "\n点取要标注检查井汇总信息的位置:")) 
  (setq x (car pt) 
        y (cadr pt) 
        i 0 
  ) 
 
  (setq ListLength (length listResult)) 
  (setvar "osmode" 0) 
 
  (setq y1 (- y (* (1+ ListLength) (* 2 #ZiGao#)))) 
  (while (<= i 2) 
   (setq x1 (+ x (* i (* 8 #ZiGao#)))) 
 
   (setq pt1 (list x1 y 0) 
         pt2 (list x1 y1 0) 
   ) 
 
   (AddLine pt1 pt2) 
   (setq i (1+ i)) 
  ) 
;;;画竖向表格线 
 
  (setq i 0) 
  (setq x1 (+ x (* 2 (* 8 #ZiGao#)))) 
  (while (<= i (1+ ListLength)) 
   (setq y1 (- y (* i (* 2 #ZiGao#)))) 
 
   (setq pt1 (list x y1 0) 
         pt2 (list x1 y1 0) 
   ) 
 
   (AddLine pt1 pt2) 
   (setq i (1+ i)) 
  ) 
;;;画横向表格线 
 
;;;------------------------------------------------------------------------ 
  (setq x1 (+ x (* 4 #ZiGao#)) 
        x2     
        (+ x (* 12 #ZiGao#)) 
        y1 
        (+ y (* #ZiGao# -1.5)) 
  ) 
 
  (setq pt1 (list x1 y1 0) 
        pt2 (list x2 y1 0) 
  ) 
 
  (command "text" "j" "c" pt1 #ZiGao# 0 "井规格") 
  (command "text" "j" "c" pt2 #ZiGao# 0 "总 数") 
  ;;输出表头 
;;;------------------------------------------------------------------------ 
  (setq i 0) 
  (setvar "dimzin" 8) 
  (while (< i ListLength) 
   (setq x1       (+ x (* 4 #ZiGao#)) 
            x2 (+ x (* 12 #ZiGao#)) 
         y1       (+ y (* #ZiGao# (- 0.5 (* 2 (+ i 2))))) 
   ) 
 
   (setq pt1 (list x1 y1 0) 
         pt2 (list x2 y1 0) 
   ) 
 
   (setq strJinType   (car (nth i listResult)) 
         intJinNumber (cadr (nth i listResult)) 
   ) 
  
   (setq sJinNumber (itoa intJinNumber)) 
 
   (command "text" "j" "c" pt1 #ZiGao# 0 strJinType) 
   (command "text" "j" "c" pt2 #ZiGao# 0 sJinNumber) 
   (setq i (1+ i)) 
  ) 
;;;打印表内容 
  (setvar "osmode" 431) 
  (princ) 
 ) 
;;;------------------------------------------------------------------------ 
 (setq ssCircles (SelectCircles "统计工程数量的井(圆)")) ; 创建井( 圆) 选择集 ssCircles,允许按圆直径条件过滤 
 (if ssCircles 
  (progn 
   (vl-cmdf "ucs" "w") 
   (setvar "osmode" 0) 
   (command "zoom" "e") 
   (princ "\n开始进行进行检查井数量统计,请稍候...") 
 
   (setq listResult nil 
         listOriginal nil 
         strTemp nil 
         intJinUndefinedNumber 0 
         intJinWithNoPipeNumber 0 
         k -1 
   ) 
   (repeat (sslength ssCircles) ; 循环与所选择的对象数量相等的次数 
    (setq strCircleEName (ssname ssCircles (setq k (1+ k)))) ; obname,取得第k个对象名 
 
    (setq listJinXData (cadr (assoc -3 (entget strCircleEName '("PS_Jin"))))) 
    (if listJinXData 
     (progn ;井类型已经设置时处理 
      (setq strJinLabel (cdr (cadr listJinXData))) 
 
      (setq floatMaxGuanJin (GetMaxGuanJin strCircleEName)) 
      (if (> floatMaxGuanJin 0) 
       (progn ;井有连接管时处理 
        (setq strTemp  (strcat strJinLabel "-" (rtos floatMaxGuanJin 2 2))) 
        ;;生成临时表,格式为:井类型-最大管径,如:检查井-800 
        (setq listOriginal (append listOriginal (list (list strTemp 1)))) 
        ;;生成初始结果表,((  井类型-最大管径 , 1   )  ) 
       ) 
 
       (setq intJinWithNoPipeNumber (1+ intJinWithNoPipeNumber)) 
      ) 
     ) 
 
     (setq intJinUndefinedNumber (1+ intJinUndefinedNumber)) 
     ;;无扩展数据时,未定义井数量加1 
    ) 
   )      ;处理选中的井,并生成井表、未定义的井数量等内容 
 
;;;------------------------------------------------------------- 
   (while (/= listOriginal nil) (SortList)) 
;;;统计管径类别及其总长,并生成结果表ResultList 
 
   (if (/= listResult nil) 
    (progn 
     (setq listResult (SortResultList listResult)) 
     (PrintList) 
      
     (if (> intJinWithNoPipeNumber 0) 
       (princ (strcat "\n选择了的井中,有"  (itoa intJinWithNoPipeNumber) "个未与管道连接!")) 
       ) 
      
     (if (> intJinUndefinedNumber 0) 
       (princ (strcat "\n选择了" (itoa intJinUndefinedNumber) "个未定义的井!")) 
       )    
    ) 
 
    (princ "\n统计出错!所有选择井均未定义或均未与管道连接!!") 
   ) 
 
   (vl-cmdf "ucs" "p") 
   (setvar "osmode" 16383) 
  ) 
 ) 
 (princ) 
) 
;;;-------------------------------------------------------------