明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4535|回复: 12

[转帖]完善实时显示钢筋面积源码

[复制链接]
发表于 2010-8-25 09:43 | 显示全部楼层 |阅读模式
在网上看到这段源码,我觉得对在设计院工作做结构的还是蛮有用处的,但是源码里面有不少错误,自己试着更了一下,还剩几个警告和错误没有处理掉,求高手帮忙看一下。
源码如下:
  1. (DEFUN C:mmkl ()
  2. (SETQ SS (SSGET "X" '((0 . "TEXT")))
  3.        I 0)
  4. (REPEAT (SSLENGTH SS)
  5.   (SETQ ENT (ENTGET (SSNAME SS I))
  6.        STR (CDR (ASSOC 1 ENT))
  7.        SL (STRLEN STR)
  8.       J 1 I (I  1))
  9.   (IF (AND (NOT (WCMATCH STR "*/*")) (WCMATCH STR "*!*")) (PROGN
  10.    (WHILE (AND (= (SETQ ST (SUBSTR STR J 1)) "0") (= (SETQ ST (SUBSTR STR J 1)) "0") (= (/ pi 2) ang 0) (list pi (  pi (/ pi 2)) 1))
  11.      ((>= pi ang (/ pi 2)) (list 0 (  pi (/ pi 2)) 1))
  12.     ((>= (  pi (/ pi 2)) ang pi) (list 0 (/ pi 2) 0))
  13.      ((>= (* 2 pi) ang (  pi (/ pi 2))) (list pi (/ pi 2) 0))
  14.    )
  15.   )
  16. )
  17.   )
  18.   )
  19.   (defun add_solid(p1 p2 p3 p4)
  20.     (entmakex (list (cons 0 "SOLID") (cons 100 "AcDbEntity") (cons 62 250) (cons 100 "AcDbTrace")
  21.                     (cons 10 p1) (cons 11 p2) (cons 12 p3) (cons 13 p4)
  22.               )
  23.     )
  24.   )
  25.   (defun add_text(pt h ang txt style jus)
  26.     (entmakex (list (cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 62 2) (cons 100 "AcDbText") (if (= jus 0) (cons 10 pt) (list 10 0.0 0.0 0.0)) (cons 40 h)
  27.                     (cons 1 txt) (cons 50 ang) (cons 7 style) (cons 72 (cond ((= jus 0) 0) ((= jus 1) 1) ((= jus 2) 1) ((= jus 3) 2))) (if (= jus 0)
  28.                     (list 11 0.0 0.0 0.0) (cons 11 pt)) (cons 100 "AcDbText") (cons 73 (cond ((= jus 0) 0) ((= jus 1) 2) ((= jus 2) 3) ((= jus 3) 2)))
  29.               )
  30.     )
  31.   )
  32.   
  33.   (defun dis (ent / obj laynm name st1 st2 st3 lst h ang n)
  34.     (setq obj (vlax-ename->vla-object ent))
  35.     (setq laynm (strcat "图层:" (dxf ent 8)) name (dxf ent 1))
  36.     ;;;;;;首先取得文字容
  37.     ;(setq tc_txt (vla-get-textstring obj))
  38.   (cond
  39.       ((wcmatch (STRCASE (dxf ent 1)) "#`%`[0-4]##,##`%`[0-4]##,##`%`[0-4]##")
  40.         (progn
  41.           ;(setq tc_mj (tc_tctc1 name))
  42.         (setq lst (list "====纵筋面积====" laynm
  43.                         ;(strcat "钢筋标注:" (vla-get-textstring obj))
  44.                         (strcat "钢筋面积:" (rtos (/ (tc_tctc1 (vla-get-textstring obj)) 100) 2 3)) "cm^2"
  45.                          ;(strcat "钢筋面积:" (rtos (vla-get-ScaleFactor obj) 2 1))
  46.                                        
  47.         ))
  48.       )
  49.       )
  50.       ((wcmatch (STRCASE (dxf ent 1)) "#`%`[0-4]##/#`%`[0-4]##,#`%`[0-4]##/##`%`[0-4]##,##`%`[0-4]##/#`%`[0-4]##;##`%`[0-4]##/##`%`[0-4]##")
  51.         (progn
  52.         (setq lst (list "====纵筋面积====" laynm
  53.                         ;(strcat "钢筋标注:" (vla-get-textstring obj))
  54.                         (strcat "钢筋面积:" (rtos (/ (tc_tctc2 (vla-get-textstring obj)) 100) 2 3)) "cm^2"
  55.                                        
  56.         ))
  57.       )
  58.       )
  59.       
  60.       ((wcmatch (STRCASE (dxf ent 1)) "`%`*[50-250]")
  61.         (progn
  62.         (setq lst (list "====板筋面积====" laynm
  63.                         ;(strcat "钢筋标注:" (vla-get-textstring obj))
  64.                         (strcat "钢筋面积:" (rtos (tc_tctc3 (vla-get-textstring obj))  2 3)) "mm^2"
  65.                                        
  66.         ))
  67.       )
  68.       )
  69. ;;;;调试部分
  70.       ((wcmatch (STRCASE (dxf ent 1)) "`%`*[50-250]`(*`)")
  71.         (progn
  72.         (setq lst (list "====箍筋面积====" laynm
  73.                         ;(strcat "钢筋标注:" (vla-get-textstring obj))
  74.                         (strcat "钢筋面积:" (rtos(/ (tc_tctc5 (vla-get-textstring obj)) 100) 2 3) "/"
  75.                         (rtos (/ (/ (* (tc_tctc5 (vla-get-textstring obj)) tc_t8)tc_t9a) 100) 2 3)) "cm^2"
  76.                                        
  77.         ))
  78.       )
  79.       )
  80. ;;;;调试部分
  81.       
  82.        ((wcmatch (STRCASE (dxf ent 1)) "#`%`[0-4]## #`%`[0-4]##,#`%`[0-4]## ##`%`[0-4]##,##`%`[0-4]## #`%`[0-4]##;##`%`[0-4]## ##`%`[0-4]##")
  83.         (progn
  84.         (setq lst (list "====纵筋面积====" laynm
  85.                         ;(strcat "钢筋标注:" (vla-get-textstring obj))
  86.                         (strcat "钢筋面积:" (rtos (/ (tc_tctc4 (vla-get-textstring obj)) 100) 2 3)) "cm^2"
  87.                                        
  88.         ))
  89.       )
  90.       )
  91.       );end cond
  92.    
  93.     (setq ss (ssadd) h (/ (getvar "viewsize") 35))
  94.     (setq ang (fx (angle (getvar "viewctr") pt)))
  95.     (setq n (* 1.4 (1+ (/ (apply 'max (mapcar 'strlen lst)) 2.0))))
  96.     (ssadd (add_solid pt (polar pt (car ang) (* n h)) (setq pt (polar pt (cadr ang) (  h (* 1.8 h (length lst))))) (polar pt (car ang) (* n h))) ss)
  97.     (setq pt (polar pt (car ang) (/ (* n h) 2)))
  98.     (if (= (caddr ang) 0)
  99.       (setq pt (polar pt (/ pi 2) (* 0.4 h)))
  100.       (setq pt (polar pt (/ pi 2) (  (* 1.4 h) (* 1.8 h (length lst)))))
  101.     )
  102.     (setq n -1)
  103.     (repeat (length lst)
  104.       (ssadd (add_text (setq pt (polar pt (  pi (/ pi 2)) (* 1.8 h))) h 0 (nth (setq n (n  1)) lst) "钢筋显示" 1) ss)
  105.     )
  106.   (vl-load-com)
  107.   (command "_.undo" "_m")
  108.   (prompt "\n***移动鼠标掠过对象查看信息!***")
  109.   (setq olderr *error* *error* myerr)
  110.   (setq oldos (getvar "osmode"))
  111.   (setq oldfill (getvar "fillmode"))
  112.   (setvar "osmode" 0)
  113.   (setvar "fillmode" 1)
  114.   (setvar "cmdecho" 0)
  115.   (tc_jzhz)
  116.   (setq ss (ssadd))
  117.   (while (not pd)
  118.     (while (not (progn
  119.                   (setq gr (grread T 1))
  120.     (if (= (car gr) 5)
  121.       (setq pt (cadr gr)
  122.             ent (nentselp pt)
  123.             ent (if (and ent (= (type (last (last ent))) 'ename))
  124.                   (last (last ent))
  125.                   (car ent)
  126.                 )
  127.       )
  128.       (setq pd T)
  129.     )
  130.          ))
  131.     )
  132.     (if (and (not pd) (not (equal ent entold)) (not (ssmemb ent ss)))
  133.       (progn
  134.         (if entold (redraw entold 4))
  135.         (if ss (command "_.erase" ss ""))
  136.         (redraw ent 3)
  137. (dis ent)
  138. (setq entold ent)
  139.       )
  140.     )
  141.   )
  142.   (if entold (redraw entold 4))
  143.   (if ss (command "_.erase" ss ""))
  144.   (setvar "osmode" oldos)
  145.   (setvar "fillmode" oldfill)
  146.   (setq *error* olderr)
  147.   (princ)
  148. )
  149. (princ)
  150. ;;下列程序与这程序类似!
  151. ;;转贴自从XDCAD,作者忘了!是你嗎?
  152. ;;当鼠标移动到满足过滤条件的像素上时,像素会闪动
  153. ;;USAGECS_EntSel "\n请选Polyline物件: " '((0 . "*Polyline")))
  154. (defun CS_ENTSEL (STR FILTER / PT SS_NAME SS)
  155.   (if (/= (type STR) 'STR)
  156.     (progn
  157.       (princ "\n变量类型不对,STR应为字符串。\n")
  158.       (eval NIL)
  159.     )
  160.     (progn
  161.       (if (/= (type FILTER) 'list)
  162. (progn
  163.    (princ "\n变量类型不对,FILTER应为表。\n")
  164.    (eval NIL)
  165. )
  166. (progn
  167.    (princ STR)
  168.    (setq PT (grread t 4 2))
  169.    (while (/= 3 (car PT))
  170.      (if (= 5 (car PT))
  171.        (progn
  172.   (setq PT (cadr PT))
  173.   (setq SS (ssget PT FILTER))
  174.   (if SS_NAME
  175.     (redraw SS_NAME 4)
  176.   )
  177.   (setq SS_NAME NIL)
  178.   (if SS
  179.     (progn
  180.       (setq SS_NAME (ssname SS 0))
  181.       (redraw SS_NAME 3)
  182.     )
  183.   )
  184.        )
  185.        (setq PT (grread t 4 2))
  186.      )
  187.    )
  188.    (setq PT (cadr PT))
  189.    (setq SS (ssget PT FILTER))
  190.    (if SS_NAME
  191.      (redraw SS_NAME 4)
  192.    )
  193.    (setq SS_NAME NIL)
  194.    (if SS
  195.      (progn
  196.        (setq SS_NAME (ssname SS 0))
  197.        (list SS_NAME PT)
  198.      )
  199.      (eval CS_NAME)
  200.    )
  201. )
  202.       )
  203.     )
  204.   )
  205. )
  206.   (defun set-description (a d /  b e)
  207.     (if (car (atoms-family 1 '("vl-load-com"))) (vl-load-com))
  208.     (setq a (vlax-ename->vla-object a))
  209.     (setq b (vla-get-Hyperlinks a))
  210.     (vlax-for item b
  211.       (vla-delete item)
  212.     )  
  213.     (setq b (vla-get-Hyperlinks a))
  214.     (setq e (vla-add b "DescriptionOnly"))
  215.     (vla-put-URLDescription e d)
  216.     (command "redraw")
  217.   )
  218. ;;;;;;=========================================
  219. ;;;;;;tc_makestyle 加载字体并作当前字体样式====
  220. ;;;;;;=========================================
  221. (defun tc_jzhz ()
  222.   (if (not (tblobjname "style" "钢筋显示"))
  223.     (entmake
  224.       '((0 . "STYLE")
  225.         (100 . "AcDbSymbolTableRecord")
  226.         (100 . "AcDbTextStyleTableRecord")
  227.         (2 . "钢筋显示")
  228.         (70 . 0)
  229.         (40 . 0)
  230.         (41 . 0.6)
  231.         (50 . 0)
  232.         (71 . 0)
  233.         (42 . 0.2)
  234.         (41 . 1)
  235.         (3 . "黑体")
  236.         ;(4 . "常规")
  237.        )
  238.     )
  239.   )
  240.   (setvar "textstyle" "钢筋显示")
  241. )
  242. ;;;;;;;;第一种钢筋面积显示已完成
  243. (defun tc_tctc1 (txt3 / N1 t1 t2 TC_GJMJ1)
  244.    (setq n1 (vl-string-search "%"  txt3)) ;在字符串中搜索指定子串的位置编号
  245.       (setq t1 (atoi (substr txt3 1 n1))            
  246.             t2 (atoi (substr txt3 6 n1)))
  247.   
  248.     (setq tc_gjmj1 (* t1 (/ (* t2 t2 3.1415926) 4)))
  249.   )
  250. ;;;;;;;
  251. (defun tc_tctc2 (txt3 / N2 t3 t4 TC_GJMJ2)
  252.    (setq n2 (vl-string-search "/"  txt3)) ;在字符串中搜索指定子串的位置编号
  253.       (setq t3 (substr txt3 1 n2)            
  254.             t4 (substr txt3 2 n2))
  255.   
  256.     (setq tc_gjmj2 (  (tc_tctc1 t3) (tc_tctc1 t4)))
  257.   )
  258. ;;;;;;
  259. (defun tc_tctc3 (txt3 / N3 N4 T5 T6 TC_GJMJ3 )
  260.    (setq n3 (vl-string-search "%"  txt3)) ;在字符串中搜索指定子串的位置号
  261.    (setq n4 (vl-string-search "@"  txt3))
  262.       (setq t5 (atof (substr txt3 (1 n3) (1- n3)))            
  263.             t6 (atof (substr txt3  (2 n4) (1- n4)))
  264. )
  265.     (setq tc_gjmj3 (* (/ 1000 t6) (/ (* t5 t5 3.1415926) 4)))
  266.   )
  267. ;;;;;;
  268. (defun tc_tctc4 (txt3 / N2 t3 t4 TC_GJMJ4)
  269.    (setq n2 (vl-string-search " "  txt3)) ;在字符串中搜索指定子串的位置编号
  270.       (setq t3 (substr txt3 1 n2)            
  271.             t4 (substr txt3 2 n2))
  272.   
  273.     (setq tc_gjmj4 (  (tc_tctc1 t3) (tc_tctc1 t4)))
  274.   )
  275. ;;;;;;
  276. (defun tc_tctc5 (txt3 / N5 N5A N6 N6A N7 N7A N8 N8A N9A TC_AREA1 TC_AREA2 TC_GJMJ5 TC_NUM1 TC_T10A TC_T7 TC_T7A TC_T9)
  277.   (setq tc_num1 (vl-string-search "/"  txt3))
  278.   (if (= tc_num1 nil)
  279.     (progn
  280.   (setq n5 (vl-string-search "%"  txt3)) ;在字符串中搜索指定子串的位置号
  281.   (setq n6 (vl-string-search "@"  txt3))
  282.   (setq n7 (vl-string-search "("  txt3))
  283.   (setq n8 (vl-string-search ")"  txt3))
  284.       (setq tc_t7 (atoi (substr txt3  (5 n5) (- n6 (5 n5)))))
  285.       (setq tc_t8 (atoi (substr txt3  (2 n6) (- n7 (1 n6))))
  286.             tc_t9 (atoi (substr txt3  (2 n7) (- n8 (1 n7))))
  287. )
  288.   (setq tc_t9a tc_t8)
  289.   (setq tc_area1 (/ (* tc_t7 tc_t7 3.1415926) 4))
  290.   (setq tc_gjmj5 (/ (* tc_area1 200 tc_t9) tc_t8))
  291. (if (>= tc_t7 10)
  292. (setq tc_gjmj5 (/ (* tc_gjmj5 300) 210))
  293. (setq tc_gjmj5 tc_gjmj5)
  294. ) ;_ 结束if
  295. (progn
  296.   (setq n5a (vl-string-search "%"  txt3)) ;在字符串中搜索指定子串的位置号
  297.   (setq n6a (vl-string-search "@"  txt3))
  298.   (setq n7a (vl-string-search "/"  txt3))
  299.   (setq n8a (vl-string-search "("  txt3))
  300.   (setq n9a (vl-string-search ")"  txt3))
  301.    
  302.         (setq tc_t7a (atoi (substr txt3 (6  n5a) (- n6a (5  n5a)))))
  303.       (setq tc_t8 (atoi (substr txt3  (2  n6a) (- n7a (1  n6a))))
  304.             tc_t9a (atoi (substr txt3  (2  n7a) (- n8a (1  n7a))))
  305.             tc_t10a (atoi (substr txt3  (2  n8a) (- n9a (1  n8a))))
  306. )
  307.   (setq tc_area2 (/ (* tc_t7a tc_t7a 3.1415926) 4))
  308.      (setq tc_gjmj5 (/ (* tc_area2 200 tc_t10a) tc_t8))
  309.      (if (>= tc_t7a 10) (setq tc_gjmj5 (/ (* tc_gjmj5 300) 210)))
  310.      ;(setq tc_gjmj6 (/ (* tc_area 200 tc_t10) tc_t9))
  311.      ;(if (>= tc_t7 10) (setq tc_gjmj6 (/ (* tc_gjmj6 300) 210)))
  312.    )))
  313.   )

 楼主| 发表于 2010-8-25 09:49 | 显示全部楼层
[检查文字 gjmj.lsp 正在加载...]
....
; 警告: 用作函数的局部变量: H
; 警告: 用作函数的局部变量: N
.......
; 错误: 表达式中有错误函数: (1 N3)
..
; 错误: 表达式中有错误函数: (5 N5)
; 检查完成.
回复 支持 0 反对 1

使用道具 举报

发表于 2021-9-29 19:58 | 显示全部楼层



结构绘图工具,查钢筋面积等。


http://atlisp.cn/package-info?name=at-structure&edition=stable
发表于 2021-9-26 23:11 | 显示全部楼层
把代码弄个压缩文件发下,这一大片很难整理。。。。

点评

啧啧啧,说话真好听  发表于 2021-9-27 20:11
 楼主| 发表于 2010-8-25 09:48 | 显示全部楼层
[检查文字 gjmj.lsp 正在加载...]
....
; 警告: 用作函数的局部变量: H
; 警告: 用作函数的局部变量: N
.......
; 错误: 表达式中有错误函数: (1 N3)
..
; 错误: 表达式中有错误函数: (5 N5)
; 检查完成.
发表于 2010-9-10 14:09 | 显示全部楼层
哎,就是很管用哈,不过还有其他的高手有类似的插件
发表于 2012-11-15 08:04 | 显示全部楼层
继续努力...
发表于 2012-11-23 23:01 | 显示全部楼层
这个是源码,高手来出手啊
发表于 2022-2-2 15:30 | 显示全部楼层
把一楼的代码整理了下

本帖子中包含更多资源

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

x
发表于 2023-3-14 12:36 | 显示全部楼层
初入宝地,都太厉害了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-7-5 14:51 , Processed in 0.177258 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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