找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 523|回复: 0

浩辰暖通4-Int4的lisp程序3

[复制链接]

已领礼包: 6个

财富等级: 恭喜发财

发表于 2005-3-10 18:32:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
(defun c:fkbj(/ ssEquipment ssWindport ent ssLen i infoList retList strOldType
              strOldSpec strOldModel strOldAirFlow strOldElevation strOldLength strOldWidth strOldHeight
              strOldCircle
              strNewSpec strNewModel strNewAirFlow strNewElevation strNewLength strNewWidth strNewHeight
              )
  (setq oldCmdecho (getvar "cmdecho"))

  (prompt "\n*** 风口编辑 ***")
  (princ "\n请选择要编辑的风口")
  ;选择有扩展数据WINDPORTKIND的块

  (setq ssWindport nil)
  (setq ssEquipment (ssget '((0 . "insert") (-3 ("WINDPORTKIND")))))
  ;取设备类别为"风口"或"风口(扩初)"的块放入ssWindport
  (if ssEquipment
    (progn
      (setq sslen (sslength ssEquipment))
      (setq i 0)
      (while (< i sslen)
        (setq ent (ssname ssEquipment i))
        (setq strWindportKind (gxdata ent "WINDPORTKIND" 0))
        (if (or (= strWindportKind "风口") (= strWindportKind "风口(扩初)"))
          (if ssWindport
            (setq ssWindport (ssadd ent ssWindport))
            (setq ssWindport (ssadd ent))
          )
        )
        (setq i (1+ i))
      )
    );end progn
  );end if ssEquipment
  (if ssWindport
    (progn
      (setq sslen (sslength ssWindport))
      (setq ent (ssname ssWindport 0))
      (setq infoList (GetWindportData ent));得到风口数据
      (setq strOldType                 (nth 0 infoList)        ;类型
            strOldSpec                (nth 1 infoList)        ;规格
            strOldModel                (nth 2 infoList)        ;型号
            strOldAirFlow        (nth 3 infoList)        ;风量
            strOldElevation        (nth 4 infoList)        ;标高
;            strOldSide                (nth 5 infoList)        ;是否侧风口
            strOldCircle        (nth 6 infoList)        ;是否圆风口
;            strOldBlockName        (nth 7 infoList)        ;块名
            strOldLength        (nth 8 infoList)        ;风口长
            strOldWidth                (nth 9 infoList)        ;风口宽
            strOldHeight        (nth 10 infoList)        ;风口高
      )
      (setq i 1)
      (while (< i sslen)
        (setq ent (ssname ssWindport i))
        (setq infoList (GetWindportData ent))
       
        (if (/= strOldType         (nth 0 infoList))        (setq strOldType ""))
        (if (/= strOldSpec         (nth 1 infoList))        (setq strOldSpec ""))
        (if (/= strOldModel         (nth 2 infoList))        (setq strOldModel ""))
        (if (/= strOldAirFlow         (nth 3 infoList))        (setq strOldAirFlow ""))
        (if (/= strOldElevation (nth 4 infoList))        (setq strOldElevation ""))
        (if (/= strOldCircle         (nth 6 infoList))        (setq strOldCircle ""))
        (if (/= strOldLength         (nth 8 infoList))        (setq strOldLength ""))
        (if (/= strOldWidth         (nth 9 infoList))        (setq strOldWidth ""))
        (if (/= strOldHeight         (nth 10 infoList))        (setq strOldHeight ""))
       
        (setq i (1+ i))
      )
      (setq RetList (WindPortEdit strOldType strOldSpec strOldModel strOldAirFlow
                      strOldElevation strOldLength strOldWidth strOldHeight strOldCircle)
      )
      (setq ;strNewType                 (nth 0 infoList)        ;类型
            strNewSpec                (nth 1 RetList)                ;规格
            strNewModel                (nth 2 RetList)                ;型号
            strNewAirFlow        (nth 3 RetList)                ;风量
            strNewElevation        (nth 4 RetList)                ;标高
            strNewLength        (nth 5 RetList)                ;风口长
            strNewWidth                (nth 6 RetList)                ;风口宽
            strNewHeight        (nth 7 RetList)        ;风口高
      )
      ;把没修改过的值置为nil
;      (if (= strOldType strNewType)                 (setq strNewType nil))
      (if (= strOldSpec strNewSpec)                 (setq strNewSpec nil))
      (if (= strOldModel strNewModel)                (setq strNewModel nil))
      ;下面的实数字符串转换成实数再转换成字符串是为了精确到2位小数
      (if (or (= strNewAirFlow "")
              (= (rtos (atof strNewAirFlow) 2 2) (rtos (atof strOldAirFlow) 2 2))
          )
        (setq strNewAirFlow nil)
      )
      (if (or (= strNewElevation "")
              (= (rtos (atof strNewElevation) 2 2) (rtos (atof strOldElevation) 2 2))
          )
        (setq strNewElevation nil)
      )
      (if (or (= strNewLength "")
              (= (rtos (atof strNewLength) 2 2) (rtos (atof strOldLength) 2 2))
          )
        (setq strNewLength nil)
      )
      (if (or (= strNewWidth "")
              (= (rtos (atof strNewWidth) 2 2) (rtos (atof strOldWidth) 2 2))
          )
        (setq strNewWidth nil)
      )
      (if (or (= strNewHeight "")
              (= (rtos (atof strNewHeight) 2 2) (rtos (atof strOldHeight) 2 2))
          )
        (setq strNewHeight nil)
      )
      ;修改风口数据
      (setq i 0 sslen (sslength ssWindport))
      (while (< i sslen)
        (setq ent (ssname ssWindport i))
        (setq strWindportKind (gxdata ent "WINDPORTKIND" 0));风口类别
        (SetWindportData ent
          strNewSpec strNewModel strNewAirFlow strNewElevation
          strNewLength strNewWidth strnewHeight strWindportKind)
        (setq i (1+ i))
      )
    );end progn
  );end if ssWindport
  
  (setvar "cmdecho" oldCmdecho)
)

;得到风口数据
(defun GetWindportData (ent / entList strType strSpec strModel strAirFlow
                        strSide strCircle strBlockName dXScale dYScale dZScale
                        attList dLength dWidth dHeight dElevation strLength
                        strWidth strHeight strElevation infoList)
  (setq entList (entget ent))
  (setq strType (gxdata ent "TYPE" 0))
  (setq strSpec (gxdata ent "SPECIFICATION" 0))
  (setq strModel (gxdata ent "WINDPORTMODEL" 0))
  (setq strAirFlow (gxdata ent "AIRFLOW" 0))
  (setq strSide (gxdata ent "SIDE" 0))
  (setq strCircle (gxdata ent "CIRCLE" 0))
  (setq strBlockName (cdr (assoc 2 entList)))
  (setq dElevation (/ (nth 3 (assoc 10 entList)) 1000))
  (setq dXScale (cdr (assoc 41 entList)))
  (setq dYScale (cdr (assoc 42 entList)))
  (setq dZScale (cdr (assoc 43 entList)))
  (setq attList (~getval strBlockName));块属性表
  (if attList
    (progn
      (setq dLength (* dXScale (nth 0 attList))
            dWidth  (* dYScale (nth 1 attList))
            dHeight (* dZScale (nth 2 attList))
      )
    )
  )
  (setq strElevation (rtos dElevation 2 2))
  (setq strLength (rtos dLength 2 2))
  (setq strWidth  (rtos dWidth 2 2))
  (setq strHeight (rtos dHeight 2 2))
  
  (setq infoList (list strType                ;类型
                       strSpec                ;规格
                       strModel                ;型号
                       strAirFlow        ;量
                       strElevation        ;标高
                       strSide                ;是否侧风口
                       strCircle        ;是否圆风口
                       strBlockName        ;块名
                       strLength        ;风口长
                       strWidth                ;风口宽
                       strheight        ;风口高
                  )
  )
)

;设置风口数据
(defun SetWindportData (ent strNewSpec strNewModel strNewAirFlow strNewElevation
                        strNewLength strNewWidth strNewHeight strWindportKind
                        / entList strBlockName dXScale dYScale dZScale attList)
  (if (= strWindportKind "风口(扩初)")
    (progn;如果是扩初风口,修改原来的扩展数据
      (setq f-ll (gxdata ent "F-LL" 1))
      (setq f-cc (gxdata ent "F-CC" 1))
      (if f-ll
        (progn
          (if strNewAirFlow (setq f-ll (list (atof strNewAirFlow) (nth 1 f-ll) (nth 2 f-ll))))
          (if strNewLength  (setq f-ll (list (nth 0 f-ll) (atof strNewLength)  (nth 2 f-ll))))
          (if strNewWidth   (setq f-ll (list (nth 0 f-ll) (nth 1 f-ll)   (atof strNewWidth))))
          (_kzsj1 ent "F-LL" f-ll)
        )
      )
      (if f-cc
        (progn
          (if strNewLength (setq f-cc (list (atof strNewLength) (nth 1 f-cc) (nth 2 f-cc))))
          (if strNewWidth  (setq f-cc (list (nth 0 f-cc) (atof strNewWidth)  (nth 2 f-cc))))
          (if strNewHeight (setq f-cc (list (nth 0 f-cc) (nth 1 f-cc)  (atof strNewHeight))))
          (_kzsj1 ent "F-CC" f-cc)
        )
      )
    )
  );end (if (= strWindportKind "风口(扩初)")
  
  ;修改新加的扩展数据
  (if strNewSpec         (_kzsj1 ent "SPECIFICATION" strNewSpec))
  (if strNewModel         (_kzsj1 ent "WINDPORTMODEL" strNewModel))
  (if strNewAirFlow        (_kzsj1 ent "AIRFLOW" strNewAirFlow))
  (setq entList (entget ent '("*")))
  (setq strBlockName (cdr (assoc 2 entList)))
  ;修改标高(即插入点的Z坐标)
  (if strNewElevation
    (progn
      (setq ptIns (assoc 10 entList))
      (setq ptIns (list (nth 0 ptIns) (nth 1 ptIns) (nth 2 ptIns) (* (atof strNewElevation) 1000)))
      (setq entList (subst ptIns (assoc 10 entList) entList))
    )
  )
  ;修改长宽高
  (setq attList (~getval strBlockName))
  (if strNewLength
    (progn
      (setq dXScale (/ (atof strNewLength) (nth 0 attList)))
      (setq entList (subst (cons 41 dXScale) (assoc 41 entList) entList))
      (if (= (gxdata ent "CIRCLE" 0) "1");如果是圆风口则长宽一起改
        (setq entList (subst (cons 42 dXScale) (assoc 42 entList) entList))
      )
    )
  )
  (if strNewWidth
    (progn
      (setq dYScale (/ (atof strNewWidth) (nth 1 attList)))
      (setq entList (subst (cons 42 dYScale) (assoc 42 entList) entList))
    )
  )
  (if strNewHeight
    (progn
      (setq dZScale (/ (atof strNewHeight) (nth 2 attList)))
      (setq entList (subst (cons 43 dZScale) (assoc 43 entList) entList))
    )
  )
  ;更新实体
  (entmod entList)
)
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2025-9-28 00:37 , Processed in 0.166006 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表