找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 598|回复: 2

[日积月累]:桩号自动增减程序

[复制链接]
发表于 2003-9-15 01:08:41 | 显示全部楼层 |阅读模式

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

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

×
;桩号自动增减程序,可以对选中桩号进行同时加、减,但请不要选非桩号文字,会进入死循环。(应同事要求编的,时间关系,还不完善)
  1. (defun *error* (msg)
  2.   (if (or
  3.         (= msg "Function cancelled")
  4.         (= msg "quit / exit abort")
  5.         (= msg "函数被取消")
  6.       )                                       ; _ end of or
  7.     (princ (strcat "\nError: " msg))
  8.   )                                       ; _ end of if

  9. )
  10. ;;; _ end of defun
  11. (defun invar ()
  12.   (setvar "cmdecho" 0)                       ; 屏蔽命令行显示
  13.   (setq os (getvar "osmode"))               ; 提取物体捕捉变量
  14.   (setvar "osmode" 0)                       ; 设置物体捕捉变量空
  15.   (setq dimzin_v (getvar "dimzin"))    ; 提取dimzin 变值
  16.   (setvar "dimzin" 8)                       ; 设置dimzin值为8,去掉后导零
  17.   (command "undo" "g")                       ; 设置“U”回的值

  18. )
  19. ;;; _ end of defun
  20. (defun revar ()
  21.   (setvar "osmode" os)                       ; 恢复物体捕捉置
  22.   (setvar "dimzin" dimzin_v)               ; 恢复dimzin的值
  23.   (command "undo" "e")                       ; 设置“U”的最点
  24.   (setvar "cmdecho" 1)                       ; 恢复命令行显示

  25. )
  26. ;;; _ end of defun
  27. (defun process_txt (txt_ss kword value_bp / i ii n txt_name txt_data o_txt_d
  28.                            o_txt_c o_txt_v n_txt_v n_txt_c n_txt_d
  29.                    )
  30.   (setq n 0
  31.         ii 0
  32.   )                                       ; _ end of setq
  33.   (repeat (sslength txt_ss)
  34.     (setq txt_name (ssname txt_ss ii))
  35.     (setq txtdata (entget txt_name))
  36.     (setq o_txt_d (assoc 1 txtdata))
  37.     (setq o_txt_c (cdr o_txt_d))
  38.     (setq iii 1)
  39.     (setq tf 1)
  40.     (setq o_txt_c_c (substr o_txt_c iii 1))
  41.     (while (= tf 1)
  42.       (progn
  43.         (setq iii (1+ iii))
  44.         (setq o_txt_c_c (substr o_txt_c iii 1))
  45.         (if (= o_txt_c_c "+")
  46.           (setq tf 0)
  47.         )                               ; _ end of if
  48.       )                                       ; _ end of progn
  49.     )                                       ; _ end of while
  50.     (setq kms (1- iii))
  51.     (setq km_c (substr o_txt_c 1 kms))
  52.     (setq m_c (substr o_txt_c (+ kms 2)))
  53.     (setq km_v (distof km_c))
  54.     (if (= m_c "000")
  55.       (setq mm_v 0)
  56.       (setq mm_v (distof m_c))
  57.     )                                       ; _ end of if
  58.     (setq m_v (+ (* km_v 1000.0) mm_v))
  59.     (setq o_txt_v m_v)
  60.     (cond
  61.       ((= kword "+")
  62.         (setq n_txt_v (+ o_txt_v value_bp))
  63.       )
  64.       ((= kword "-")
  65.         (setq n_txt_v (- o_txt_v value_bp))
  66.       )
  67.     )                                       ; End of cond
  68.     (setq km_c (rtos (fix (/ n_txt_v 1000.0)) 2 0))
  69.     (if (>= n_txt_v 1000.0)
  70.       (setq m_c (substr (rtos n_txt_v 2) (1+ (strlen km_c)))) ; _ end of
  71.                                        ; setq
  72.       (setq m_c (rtos n_txt_v 2))
  73.     )                                       ; _ end of if
  74.     (if (= (distof m_c 2) 0.0)
  75.       (setq m_c "000")
  76.     )                                       ; _ end of if
  77.     (setq n_txt_c (strcat km_c "+" m_c))
  78.     (setq n_txt_d (cons 1 n_txt_c))
  79.     (setq txtdata (subst
  80.                     n_txt_d
  81.                     o_txt_d
  82.                     txtdata
  83.                   )
  84.     )
  85.     (entmod txtdata)
  86.     (setq n (1+ n))
  87.     (setq ii (1+ ii))
  88.   )                                       ; end of repeat
  89.   (prin1 "成功对")
  90.   (prin1 n)
  91.   (prin1 "个数字进行了操作!")
  92. )
  93. ;;; end of subprogram
  94. (defun c:zhxg ()
  95.   (invar)
  96.   (prompt "\n请选取桩号:")
  97.   (terpri)
  98.   (setq ss_txt (ssget '((0 . "text"))))        ; 选取并过滤为文字
  99.   (initget "+ - ")
  100.   (setq p_kword (getkword "\n 请输入操作码: 加(+)、减(-)<+>")) ; _ end of
  101.                                        ; setq
  102.   (if (null p_kword)
  103.     (setq P_kword "+")
  104.   )                                       ; _ end of if
  105.   (initget (+ 1 2))
  106.   (setq bp_value (getreal "\n 请输入加、减数:"))
  107.   (process_txt ss_txt p_kword bp_value)
  108.   (revar)
  109. )
  110.                                         ;end of main program
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2005-1-16 16:43:19 | 显示全部楼层

请把桩号精确到小数点后3位

请把桩号精确到小数点后3位
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-1-16 17:25:16 | 显示全部楼层
谢谢1楼提供的好东东!
但还需要不断优化。。辛苦了1!!!!!!!!!!!!!!!!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-9-27 19:23 , Processed in 0.320082 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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