www.pudn.com > CADtool.rar > PS_yskbz.lsp, change:2008-10-20,size:12952b


;;; ------------------------------------------------------------------------- 
;;;雨水口布置 
(defun C:PS_yskbz (/            jpoint       jppoint      k            kjp          lpjp 
                    obc          oblname      obname       obstr        w            ag ;切线角度 
                    ZhuoYou ;点在道路左侧还是右侧 
                    nthJinList   JinList 
                    ;;记录未分左右侧时的井表 
                    zJinList ;左侧井表 
                    mJinList ;中线上井表 
                    yJinList ;右侧井表 
                    ListTemp     QiDianLiCheng             LiChengFangXiang 
                    ZhongDianLiCheng          LZhongXiang ;与中线相关变量 
                    BasicPoint   tPoint ;雨水口插入基点  及  基线方向上一点 
                    BiZiNumber   BiZiName ;雨水口箅子个数  箅子名 
                    ContinueBZ ;控制是否继续布置雨水口 
                    JinTypeNumber ;整数,记录左、中、右侧三种类型井的总数目 
                    Bili ;绘雨水口的比例 
                   ) 
;;;-------------------------------------------------------------       
;;;批量绘雨水口  调用参数( 井表 井信息字符串 ) 
 (defun PiLiangBuYSK (JList        str          /            licheng      k            i 
                      mstr         ZhuoYou      tmpNumber ;临时变量,数值 
                      YSKDistList ;雨水口基点到中线距离表 
                      YSKList ;雨水口或井特征表 ( ( 到中线距离 井或雨水口类别  基点 基线角 ) ) 
                      YSKPointList ;雨水口基点表 
                      pt           pt1          jpPoint      agT          agtmp        ListTmp 
                      TypeStr      JinZhuoYouStr ;用于生成雨水口或井特征表的中间数据 
                      bzZhuoYou    disToZhongXiang ;用于生成雨水口或井特征表的中间数据 
                      bPlotLiangJieGuan ;控制是否绘制雨水口连接管 
                     ) 
  (setq YSKDistList nil 
        YSKList nil 
        YSKPointList nil 
        k 1 
        tmpNumber 1.0 
        ZhongGuanChang 0.0 
  ) 
 
  (while tmpNumber 
   (setq mstr (strcat "\n请输入" 
                      str 
                      "检查井第" 
                      (rtos k 2 0) 
                      "行雨水口基点(相对于路中线,最外侧边线的中点)到路中线距离(左正右负,回车结束输入):" 
              ) 
   ) 
 
   (if (setq tmpNumber (getreal mstr)) 
    (setq YSKDistList (append YSKDistList (list tmpNumber))) 
   ) 
   (setq k (+ 1 k)) 
  ) 
 
  (setq k 0) 
  (if YSKDistList 
   (progn ;有输入值时 
    (initget "Y N _Yes No") 
    (if (not   (setq bPlotLiangJieGuan (getkword "\n绘雨水口时,是否绘连接管[是(Y)/否(N)]<Y>:")) ) 
     (setq bPlotLiangJieGuan "Yes") 
     ) 
 
    (repeat (length JList) 
     ;;------------------------------------------------------------------ 
     ;;井表 (井对象名,里程,左右侧字串,井中心坐标表 ,井中心里程里程正向的中线切线角 ) 
     (setq licheng (nth 1 (nth k JList))) 
     (setq ZhuoYou (nth 2 (nth k JList))) 
     (setq pt (nth 3 (nth k JList))) 
     (setq agT (nth 4 (nth k JList))) 
    ; (setq agT (/ (* 180.0 agT) pi ) ) 
     (setq jpPoint (vlax-curve-getClosestPointTo oblname pt T)) 
     (setq disToZhongXiang (distance pt jpPoint)) 
     (if (= ZhuoYou "右侧") 
      (setq disToZhongXiang (- disToZhongXiang)) 
     ) 
     (setq YSKList (list (list disToZhongXiang "井" pt agT))) 
     ;;以上生成井在雨水口及井信息表中,井的信息 
     ;;------------------------------------------------------------------ 
     (setq i 0) 
     (repeat (length YSKDistList) ;生成井在雨水口及井信息表中,雨水口的信息 
      (setq disToZhongXiang (nth i YSKDistList)) 
      (if (< disToZhongXiang 0) 
       (progn 
        (setq bzZhuoYou "右侧") 
        (setq agtmp agT) 
       ) 
 
       (progn 
        (setq bzZhuoYou "左侧") 
        (setq agtmp (+ agT pi)) 
       ) 
      ) 
 
      (setq pt (car (getPointByLiChengZhuoYouJuLi 
                     oblname            LZhongXiang        QiDianLiCheng      LiChengFangXiang 
                     ZhongDianLiCheng   licheng            bzZhuoYou        (abs  disToZhongXiang) 
                    ) 
               ) 
      ) 
      (setq YSKList (append YSKList 
                            (list 
                             (list disToZhongXiang "雨水口" pt agtmp) 
                            ) 
                    ) 
      ) 
 
      (setq i (+ 1 i)) 
     ) 
 
    (setq YSKList (vl-sort YSKList 
                           (function (lambda (e1 e2) 
                                     (>= (car e1) (car e2)) 
                                     ) 
                            ) 
                   ) 
     )    ;对信息表按与中线距离由大于小进行排序 
     ;;------------------------------------------------------------------ 
     ;;生成雨水口及连接管 
     (setq ListTmp (nth 0 YSKList)) 
     (setq TypeStr (nth 1 ListTmp)) 
     (setq pt (nth 2 ListTmp)) 
     (setq agtmp (nth 3 ListTmp)) 
 
     (if (= TypeStr "雨水口") 
     ( InsertBlock  BiZiName  pt  agtmp )   
     ) 
 
     (setq i 1) 
     (repeat (- (length YSKList) 1) 
      (setq ListTmp (nth i YSKList)) 
      (setq TypeStr (nth 1 ListTmp)) 
      (setq pt1 (nth 2 ListTmp)) 
      (setq agtmp (nth 3 ListTmp)) 
 
      (if (= TypeStr "雨水口") 
      ( InsertBlock  BiZiName  pt1  agtmp )   
      ) 
      (if (= bPlotLiangJieGuan "Yes") 
        (progn 
         (AddLine pt pt1 ) 
         (setq ZhongGuanChang (+ ZhongGuanChang (distance pt pt1))) 
         ) 
        ) 
      (setq pt pt1) 
 
      (setq i (+ 1 i)) 
     ) 
 
     ;;------------------------------------------------------------------ 
     (setq k (+ 1 k)) 
    ) 
    (if (= bPlotLiangJieGuan "Yes") 
     (princ (strcat "\n本次共绘制" 
                   str 
                   "检查井与雨水口间的连接管" 
                   (rtos ZhongGuanChang 2 2) 
                   "米" 
           ) 
     ) 
    ) 
   ) 
   ;;------------------------------------------------------------------ 
   (princ "\n未输入任何雨水口布置位置!") ;无输入值时 
  ) 
 ) 
 
;;;------------------------------------------------------------- 
 (setq BiZiNumber 1 
       Bili 1 ;绘雨水口的比例 
       BiZiName "DanBi" 
       ContinueBZ "Yes" 
       ListTemp nil 
 ) 
 (MakeYSKBlock BiZiNumber BiZiName Bili ) ;制作单箅雨水口图块 
 (setvar "osmode" 16383) 
 
 (while (= ContinueBZ "Yes") 
  (initget "S P _Set Piliang") 
  (setq BasicPoint (getpoint 
                    "\n点取一点作为雨水口最外侧边线中点:[设置雨水口类型(S)/批量布置雨水口(P)/回车退出]:" 
                   ) 
  ) 
  (cond 
   ((and  (listp BasicPoint) BasicPoint );输入值为点时 
    (setq tPoint (getpoint BasicPoint "\n点取另一点确定雨水口最外侧边线的方向:")) 
    (if tPoint 
     (progn 
      (setq ag (angle BasicPoint tPoint)) 
       ( InsertBlock  BiZiName  BasicPoint  ag )   
     );基点及切线上点输入正确时执行 
 
     (setq ContinueBZ "Stop") ;输入点不正确时,退出程序 
    )  
   )     
 
   ((= BasicPoint "Set") ;设置雨水口的类型:单箅、双箅、多箅 
    (initget 6) 
    (setq BiZiNumber (getint 
                      "\n需要布置的雨水口箅子数为[单箅(1)/双箅(2)/多箅(3)]<1>:" 
                     ) 
    ) 
    (cond 
     ((= BiZiNumber 2) (setq BiZiName "ShuanBi")) 
     ((= BiZiNumber 3) (setq BiZiName "DuoBi")) 
     (T (setq BiZiNumber 1) (setq BiZiName "DanBi")) 
    ) 
 
    (MakeYSKBlock BiZiNumber BiZiName Bili ) 
   ) 
 
   ((= BasicPoint "Piliang") ;批量布置雨水口 
    (setq obc (SelectCircles "布置雨水口的井(圆)")) 
          ; 创建井( 圆) 选择集 obc,允许按圆直径条件过滤 
 
    (if (not ListTemp) ;设置路中线及相关信息 
     (setq ListTemp (GetZhongXiang "否")) ;设置路中线及相关信息 
 
     (progn 
      (initget "Y N") 
      (setq W (getkword 
               "\n已定义道路中线,是否重新定义[是(Y)/否(N)]<N>:" 
              ) 
      ) 
 
      (if (= W "Y") 
       (setq ListTemp (GetZhongXiang "否")) ;设置路中线及相关信息 
      ) 
     ) 
    ) 
 
    (if (and obc ListTemp) ;如果选择有井,且成功设置中线 
     (progn 
      (setq oblname          (nth 0 ListTemp) 
            QiDianLiCheng    (nth 1 ListTemp) 
            LiChengFangXiang (nth 2 ListTemp) 
            ZhongDianLiCheng (nth 3 ListTemp) 
            LZhongXiang      (nth 4 ListTemp) 
      )   ;确定:( 中线  中线起点里程  里程增加与曲线正向的关系  终点里程  中线长 ) 
      (setq k -1 
            JinList nil 
      ) 
      (repeat (sslength obc) ; 循环与所选择的对象数量相等的次数 
       (setvar "osmode" 0) 
       (setq obname (ssname obc (setq k (1+ k)))) ; obname,取得第k个对象名 
       (setq obstr (entget obname)) 
       (setq jPoint (cdr (assoc 10 obstr))) ; 取得井中心坐标 
       (setq jpPoint (vlax-curve-getClosestPointTo oblname jPoint T)) 
          ; 取得井圆心与中线的垂足坐标 
       (setq LPJP (vlax-curve-getDistAtPoint oblname jpPoint)) 
 
       (if (= LiChengFangXiang "同向") 
        (setq KJP (+ QiDianLiCheng LPJP)) 
        (setq KJP (- QiDianLiCheng LPJP)) 
       )  ; 计算井的里程数值 
       (if (<= (distance jPoint jpPoint) 0.5) 
          ;点到中线距离小于或等于0.5时,也看作为在路中线上 
        (setq ZhuoYou "在中线上") 
        (setq ZhuoYou (strZhuoYou oblname jPoint jpPoint LPJP LiChengFangXiang)) 
       )  ;判断点在道路左右侧 
       (setq ag (AngleQieXiang oblname jpPoint)) ;计算切线角 
       (if (/= LiChengFangXiang "同向") 
        (setq ag (+ pi ag)) 
       )  ;计算与里程增加方向正向的切线角 
 
       (setq JinList (append JinList (list (list obname KJP ZhuoYou jPoint ag)))) 
       ;;生成表 (井对象名,里程,左右侧字串,井中心坐标表 ,井中心里程里程正向的中线切线角 ) 
      ) 
          ;;准备必要的初始化条件,并生成 (井对象名,里程,左右侧字串,井中心坐标表 ,井中心里程里程正向的中线切线角 )表 
 
      (setq JinList (JinListSorted JinList "增加方向")) 
      ;;------------------------------------------------- 
      ;;以下把井表按在道路左中右侧分为三个表 
      (setq k -1) 
      (setq zJinList nil 
            mJinList nil 
            yJinList nil 
            JinTypeNumber 0 
      ) 
 
      (repeat (length JinList) ; 循环与所选择的对象数量相等的次数 
       (setq nthJinList (nth (setq k (1+ k)) JinList)) ;取得第k个井表 
       (setq ZhuoYou (caddr nthJinList)) 
       (cond 
        ((= ZhuoYou "左侧") 
         (setq zJinList (append zJinList (list nthJinList))) 
        ) 
        ((= ZhuoYou "右侧") 
         (setq yJinList (append yJinList (list nthJinList))) 
        ) 
        (T (setq mJinList (append mJinList (list nthJinList)))) 
       ) 
      ) 
 
      (if zJinList 
       (setq JinTypeNumber (+ JinTypeNumber 1)) 
      ) 
      (if mJinList 
       (setq JinTypeNumber (+ JinTypeNumber 1)) 
      ) 
      (if yJinList 
       (setq JinTypeNumber (+ JinTypeNumber 1)) 
      ) 
      ;;计算左中右三种井的井类型总数 
      ;;------------------------------------------------- 
      (if (= JinTypeNumber 1) 
       (PiLiangBuYSK JinList "") 
 
       (progn 
        (if zJinList 
         (PiLiangBuYSK zJinList "左侧") 
        ) 
        (if mJinList 
         (PiLiangBuYSK mJinList "中线上") 
        ) 
        (if yJinList 
         (PiLiangBuYSK yJinList "右侧") 
        ) 
       ) 
      ) 
      ;;------------------------------------------------- 
     ) 
    ) 
   ) 
 
   (T (setq ContinueBZ "Stop")) ;输入为空时,退出程序 
  ) 
 ) 
 (setvar "osmode" 16383) 
 (princ) 
) 
;;;------------------------------------------------------------- 
;;;生成雨水口块,块名为 DanBi ShuanBi DuoBi 
;;;调用参数 (  箅数 , 绘图比例   ) 
(defun MakeYSKBlock (BiZiNumber BiZiName Bili  ; 雨水口箅子数量: 1 2 3 
                     / BasicPoint n idList a b ; a  b 为雨水口单个箅子长及宽 
) 
;;;------------------------------------------------------------- 
;;;生成箅子组件及块基点 
 (defun MakeEntityNameList (BNumber a b / idr k pt) 
  (setq pt (list a b)) 
  (vl-cmdf "rectang" '(0 0) pt ) 
  (setq idr (entlast)) 
  (vl-cmdf "hatch" "s" idr "" ) 
  (setq idList (list (entlast))) 
  (entdel idr) 
 
  (setq pt (list (* (* 2 BNumber) a) b)) 
  (vl-cmdf "rectang" '(0 0) pt ) 
  (setq idr (entlast)) 
 
  (setq k 1) 
  (while (< k BNumber) 
   (setq pt (list (* (* 2 k ) a)  0)) 
   (command "copy"  (nth 0 idList)  ""  '(0 0)   pt ) 
   (setq idList (append idList (list (entlast)))) 
   (setq k (+ 1 k)) 
  ) 
  (setq idList (append idList (list idr))) 
  (setq BasicPoint (list (* BNumber a) 0)) 
 ) 
;;;------------------------------------------------------------- 
 (command "-layer" "m" "雨水口及连接管" "") 
 (setq a 0.9 
       b 0.75 
 )        ;定义绘图比例为1:500时,单箅的长及宽 
 (setq a (* a Bili) 
       b (* b Bili) 
 ) 
 (setvar "osmode" 0) 
 
 (if (not (tblsearch "block" BiZiName)) 
   (progn 
    (MakeEntityNameList BiZiNumber a b) 
    (command "-block" BiZiName BasicPoint ) 
    (setq n 0) 
    (repeat (length idList) 
     (command (nth n idList)) 
     (setq n (+ 1 n)) 
    ) 
    (command "") 
   ) 
 )       ;制作箅子块 
 
 (setvar "osmode" 431) 
) 
;;;-------------------------------------------------------------