明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1159|回复: 6

Cass土方5米方格网节点数字转块

[复制链接]
发表于 2019-6-25 23:24 | 显示全部楼层 |阅读模式
本帖最后由 树櫴希德 于 2019-7-1 20:26 编辑

  1. ;;name:BF-list-delsame
  2. ;;;desc:删除表中相同元素,保留第一次出现的位置
  3. ;;;arg:lst:列表
  4. ;;;arg:buzz:容差
  5. ;;;return:删除重复元素组成的表
  6. ;;;exampleBF-list-delsame '(0 1 2 3 2 4 4) 0.1)---->(0 1 2 3 4)
  7. (defun BF-list-delsame (lst buzz)
  8.   (if Lst
  9.     (cons (car Lst)
  10.    (BF-list-delsame
  11.      (vl-remove-if
  12.        '(lambda (x) (equal (car lst) x buzz))
  13.        (cdr lst)
  14.      )
  15.      buzz
  16.    )
  17.     )
  18.   )
  19. )

  20. ;货物分两组(样品 库存)
  21. (defun lst22(lst / lst1 lst2)
  22.   (setq lst1 '() lst2 '())

  23.   (mapcar'(lambda(a)
  24. (if (member a lst2)
  25.       (setq lst1 (cons a lst1))
  26.       (setq lst2 (cons a lst2))
  27.     )

  28.       )lst)

  29. (cons (reverse lst2) (reverse lst1))
  30. )
  31. ;;;;;;
  32. (defun lst->2lst(lst / lst1 lst2 x y)
  33.   (setq lst1 '() lst2 '())

  34. (mapcar'(lambda(x)
  35.     (mapcar'(lambda(Y)
  36. (if  (equal (distance (car x) (car y) ) 0.000 0.01000)
  37.   (progn  (setq lst1 (append  x (list(last y) ) ) )
  38.         (setq lst (vl-remove y lst))    )
  39.   )         
  40.         )  (vl-remove x lst)  )
  41.    
  42. (setq lst2 (cons lst1 lst2))
  43.     (setq lst (vl-remove x lst))
  44.     )LST)

  45.    lst2  ;(cadr(lst=====2lst lst2) )


  46. )

  47. ;;;;;;;;;;;;;
  48. (defun mkgcd (inspt height height-1  height-2 scale  / pt  pt1 blkdef obj)
  49. (gc)  (vl-load-com)
  50.   (setvar "CMDECHO" 0)
  51.   (command "layer" "m" "检查高程点" "c" "1" "" "L" "CONTINUOUS" ""  "")
  52. (cond ((= (type height) REAL) (setq height (rtos height 2 3))  )
  53.      ((= (type height) STR) (setq height height)  )

  54. ((= (type height-1) REAL) (setq height-1 (rtos height-1 2 3))  )
  55.      ((= (type height-1) STR) (setq height-1 height-1)  )

  56.       
  57. ((= (type height-2) REAL) (setq height-2 (rtos height-2 2 3))  )
  58.      ((= (type height-2) STR) (setq height-2 height-2)  )
  59.   )
  60.   ;;;;-------------
  61. ; (if height     (setq height (rtos height 2 3))      (setq height  "")   )
  62. ;(if height-1     (setq height-1 (rtos height-1 2 3))     (setq height-1 "")   )
  63.   ;;;;-------------
  64.   (regapp "SOUTH")
  65.   ;;;检查字体 "HZ" 是否存在
  66.   (if (not (tblobjname "style" "HZ"))
  67.     (command "style" "HZ" "rs.shx,hztxt.shx" 0 1 0 "" "" "")
  68.   )
  69. (if (not (tblobjname "style" "宋体"))
  70.     (command "-style" "宋体" "宋体" 0 1 0 "" "" "")
  71.   )

  72.   
  73.   ;;;检查是否存在高程点图块定义
  74.   (if (not (tblobjname "block" "GC200"))
  75.     (progn
  76.       (setq blkdef (vla-Add (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-3D-point '(0 0 0)) "GC200"))
  77.       (setq obj
  78.         (vla-AddPolyline
  79.            blkdef
  80.            (vlax-make-variant
  81.               (vlax-safearray-fill
  82.                  (vlax-make-safearray vlax-vbdouble (cons 0 5))
  83.                  '(-0.2 0 0 0.2 0 0)
  84.               )
  85.            )
  86.         )
  87.       )
  88.       (vla-SetBulge obj 0 1) (vla-SetBulge obj 1 1)
  89.       (vla-put-Closed obj :vlax-true)
  90.       (vla-put-ConstantWidth obj 0.4)
  91.     )
  92.   )
  93.   ;;;插入块
  94.   (entmake (list
  95.              '(0 . "INSERT")
  96.              '(100 . "AcDbEntity")
  97.              '(100 . "AcDbBlockReference")
  98.              '(66 . 1);;;属性跟随标志,1跟随,0不跟随
  99.               (cons 2 "GC200")
  100.               (cons 10 inspt)
  101.               (cons 41 scale)
  102.               (cons 42 scale)
  103.               (cons 43 scale)
  104.               '(-3 ("SOUTH" (1000 . "84848412")))
  105.            )
  106.   )
  107.   ;;;插入属性
  108.   (entmake (list
  109.              '(0 . "ATTRIB")
  110.              '(100 . "AcDbEntity")
  111.              '(100 . "AcDbText")
  112.               (cons 10 (setq pt (polar inspt (* 0.5 PI) (* 1.8 scale))))
  113.               (cons 40 (* 2.0 scale))
  114.               (cons 50 0)
  115.                (cons 62 3)
  116.               (cons 41 0.8)
  117.               (cons 51 0)
  118.               (cons 1 height)
  119.               (cons 7 "宋体")
  120.               (cons 72 0)
  121.               (cons 11 pt)
  122.               '(100 . "AcDbAttribute")
  123.               (cons 2 "height")
  124.               (cons 70  0)
  125.               (cons 74 2)
  126.            )
  127.    )
  128. ;;;;;;;;;;;;;;;;;;;;;;;
  129.   (entmake (list
  130.              '(0 . "ATTRIB")
  131.              '(100 . "AcDbEntity")
  132.              '(100 . "AcDbText")
  133.               (cons 10 (setq pt1 (polar inspt (* -0.5 PI) (* 1.8 scale))))
  134.               (cons 40 (* 2.0 scale))
  135.               (cons 50 0)
  136.                (cons 62 3)
  137.               (cons 41 0.8)
  138.               (cons 51 0)
  139.               (cons 1 height-1)
  140.               (cons 7 "宋体")
  141.               (cons 72 0)
  142.               (cons 11 pt1)
  143.               '(100 . "AcDbAttribute")
  144.               (cons 2 "height-1")
  145.               (cons 70  0)
  146.               (cons 74 2)
  147.            )
  148.    )

  149.   ;;;;;;;;;;;;;;;;;;;;;;;
  150.   (entmake (list
  151.              '(0 . "ATTRIB")
  152.              '(100 . "AcDbEntity")
  153.              '(100 . "AcDbText")
  154.               (cons 10 (setq pt1 (polar inspt (* 1.0 PI) (* 7.0 scale))))
  155.               (cons 40 (* 2.0 scale))
  156.               (cons 50 0)
  157.                (cons 62 3)
  158.               (cons 41 0.8)
  159.               (cons 51 0)
  160.               (cons 1 height-2)
  161.               (cons 7 "宋体")
  162.               (cons 72 0)
  163.               (cons 11 pt1)
  164.               '(100 . "AcDbAttribute")
  165.               (cons 2 "height-2")
  166.               (cons 70  0)
  167.               (cons 74 2)
  168.            )
  169.    )
  170. ;;;插入属性

  171.   
  172.   
  173.   
  174.    ;;;结束标志
  175.    (entmake '((0 . "SEQEND")))
  176.    (princ)
  177. )
  178. ;;;;;;;;;;;


  179. ;;by Gu_xl

  180. ;;;;;;;;;;;;;
  181. (defun cx-ss2en
  182.   (ss / enlst)
  183.   (cond
  184.     ((= (type ss) 'PICKSET)
  185.       (vl-remove-if-not '(lambda (x) (= (type x) 'ENAME)) (mapcar 'cadr (ssnamex SS)))
  186.     )
  187.     ((= (type ss) 'LIST)
  188.       (setq enlst (ssadd))
  189.       (last (mapcar '(lambda (x) (ssadd x enlst)) ss))
  190.     )
  191.     ((='ename(type ss))
  192.       (ssadd ss)
  193.     )
  194.   )
  195. )
  196. ;;;;;;;;;;;;;
  197. (defun subtotals(lst m ns / myfun a b c);;对lst以子表第m项为关键字进行分类,ns为整数时记录第ns项、为表(2 3)记录表中指定的项、为空记录关键字以外所有项
  198.   (cond((=(type ns)'LIST)(defun myfun(x)(list(mapcar'(lambda(y)(nth y x))ns))))
  199.        ((=(type ns)'INT)(defun myfun(x)(LIST(NTH ns x))))
  200.        (t(defun myfun(x)(list(vl-remove c x)))))
  201.   (foreach x lst
  202.     (setq a(if(setq c(nth m x)b(assoc c a))
  203.        (subst(append b(myfun x))b a)
  204.        (append a(list(append(list c)(myfun x))))))))

  205. ;(foreach x(vl-remove-if'(LAMBDA(x)(<(length x)3)) (SUBTOTALS(mapcar'(lambda(x)(setq p(cdr(assoc 10(entget x))))
  206.        ;(list(list(car p)(cadr p))(last p)))  (sstoes(ssget"X"'((8 . "GCD")))))0 1))
  207.     ;(gxl-cs:gcd x scale))



  208. ;(nth 10(SUBTOTALS(mapcar'(lambda(p)  (list(list(car p)(cadr p))(last p)))  b3) 0 1) )


  209. ;(cdr(assoc 10(entget (car(entsel)))))

  210. ;(command "pline" (getpoint)(cdr(assoc 11(entget (car(entsel))))) "")

  211. ;(command "pline" (getpoint)(cdr(assoc 10(entget (car(entsel))))) "")


  212. ;;;;;;;;;;;;;;;;;;
  213. (defun insertgc ( e / e)
  214.   (cdr(assoc 10(entget e)))
  215.   )
  216. (defun insertgc11 ( e / e)
  217.   (cdr(assoc 11(entget e)))
  218.   )

  219. (defun insert1 ( e / e)
  220.   (distof (cdr(assoc 1(entget e))) 2 )
  221.   )
  222. ;;;;;;;;;;;;;;;;;;;;;
  223. (defun c:chd ( / ssa ssb b1 b2 zba zba1 zba2 zbb zbb1 zbb2 b3 pzx123 p pzx1234)
  224. (setq ssa (ssget "x"'( (0 . "text") (62 . 2) (8 . "fgw") ) ) ) ;

  225. (setq ssb (ssget "x"'( (0 . "text") (62 . 4) (8 . "fgw") ) ) )
  226. (setq b1 nil) (setq b2 nil)
  227. ;(setq zbba (mapcar '(lambda (x) ) )       )

  228. (foreach x (cx-ss2en ssa)

  229.     (setq zba (insertgc x)) (setq zba1 (insert1 x)) (setq zba2 (list (-(car zba)0.250) (-(cadr zba)0.250) zba1)) (setq b1 (append b1 (list zba2 )) )
  230.    )
  231. (foreach x (cx-ss2en ssb)

  232.     (setq zbb (insertgc11 x)) (setq zbb1 (insert1 x)) (setq zbb2 (list (-(car zbb)0.250) (+(cadr zbb)0.250) zbb1)) (setq b2 (append b2 (list zbb2 )) )
  233.    )

  234. ;(setq b3 (car(lst22(append b1 b2))))
  235.   (setq b3 (BF-list-delsame (append b1 b2) 0.010))
  236. ;(setq pzx1 (mapcar'(lambda(x)  (setq pzx (cons (list (car x) (cadr x)) (list(nth 2 x)) )) )b3 ))

  237. (setq pzx123 (vl-remove-if'(LAMBDA(x)(<(length x)3))  (lst->2lst(mapcar'(lambda(p)  (list(list(car p)(cadr p))(last p)))  b3) )  )   )

  238. ;(mapcar'(lambda(x)  (gxl-cs:gcd x 0.5 ) )pzx123 );;;inspt height height-1 scale


  239. (mapcar'(lambda(x)  (mkgcd (car x) (rtos (cadr x) 2 3)  (rtos (caddr x) 2 3)  (rtos (- (cadr x)(caddr x) ) 2 3 ) 0.1 ) ) pzx123 )




  240. ;(setq pzx1234 (reverse(vl-sort (mapcar'(lambda(p)  (list(list(car p)(cadr p))(last p)))  b3) (function (lambda (e1 e2) (equal (distance (car e1) (car e2) ) 0.000 0.001000)   ) ) )  ) )




  241. (defun xl-div (lst x / lst2)
  242.   (foreach n lst
  243.     (if        (and lst2 (/= x (length (car lst2))))
  244.       (setq lst2 (cons (append (car lst2) (list n)) (cdr lst2)))
  245.       (setq lst2 (cons (list n) lst2))
  246.     )
  247.   )
  248.     (reverse lst2)

  249. )
  250. ;(mapcar'(lambda(x)   (mkgcd  (caar x)    (rtos (cadar x) 2 3)  (rtos (cadadr x) 2 3)   (rtos (- (cadar x) (cadadr x)  ) 2 3)   0.1)     )   (vl-remove-if'(LAMBDA(x)(<(length x)2)) (xl-div pzx1234 2)) )
  251. (princ)
  252.   )


本帖子中包含更多资源

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

x
 楼主| 发表于 2019-6-26 20:09 | 显示全部楼层
本帖最后由 树櫴希德 于 2019-6-28 20:26 编辑

样板+样图 任然有重合点 望大神修改

本帖子中包含更多资源

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

x
 楼主| 发表于 2019-6-25 23:25 | 显示全部楼层
我也不知道有什么用

本帖子中包含更多资源

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

x
发表于 2019-6-26 08:04 | 显示全部楼层
大神,给您提供一个编程的方向,就是多段线批量标注节点号(能选择每点标或隔几点标最好),并标示出点位(用点)(要修改可自己在点样式里改),同时导出对应坐标到CSV或TXT,要求支持自定义坐标(如我重新定义了某条断面的原点)。这个插件如果搞好了,非常利于做断面资料或竣工资料。谢谢!
发表于 2019-6-27 16:14 | 显示全部楼层
自身方格网的节点不重合就行啦,要保证方格网两个节点之间的文字不重合难。
 楼主| 发表于 2019-6-28 17:52 | 显示全部楼层

批量文字插入?
  1. (defun str1 (str num addstr / LEN STR1 STR2 pzx)
  2.   (if (< num 1) (progn (setq pzx (strcat addstr str)))
  3. (progn
  4.      (setq len (strlen str)) ;字符长度
  5.   (setq str1 (substr str 1 num))
  6.   (setq str2 (substr str (+ num 1) (- len num)))
  7.   (setq pzx(strcat str1 addstr str2) )
  8.   )

  9.     )
  10. pzx
  11. )
  12. (defun SstoEs(ss / a en lst)
  13.   (if ss(progn(setq a -1)
  14. (while(setq en(ssname ss(setq a(1+ a))))
  15.    (setq lst(cons en lst)))))
  16.   lst)
  17. (setq num(getint "\n请输入插入序号:"))

  18. (setq addstr(getstring "\n请输入需要插入的文字:") )

  19.     (mapcar'(lambda(x)(setq p(cdr(assoc 1(entget x)))) (setq p1(str1 p num addstr))
  20.      (entmod (subst (cons 1 p1) (assoc 1(entget x))  (entget x) ) )
  21.         
  22.        )  (sstoes(ssget"X"'((0 . "TEXT") ))) )
  23.       

 楼主| 发表于 2020-12-26 10:20 | 显示全部楼层
bgc数字转高程
  1. ;;;by Gu_xl
  2. (defun gxl-cs:gcd (inspt height scale / pt blkdef obj);展高程点函数(inspt:插入点,heitht:高程值,scale:缩放比例,xsws:高程注记位数)
  3. (vl-load-com) ;将 Visual LISP 扩展功能加载到 AutoLISP
  4.   (regapp "SOUTH")
  5.   (setvar "CMDECHO" 0)
  6.   (command "layer" "m" "GCD" "c" "1" "" "L" "CONTINUOUS" ""  "")
  7.   (if height
  8.     (setq height (rtos height 2 3));3为高程注记位数
  9.     (setq height "")
  10.   )
  11.   (regapp "SOUTH")
  12.   
  13.   ;;;检查字体 "HZ" 是否存在
  14.   (if (not (tblobjname "style" "宋体"))
  15.     ;(command "style" "HZ" "rs.shx,hztxt.shx" 0 1 0 "" "" "")
  16.     (command "style" "宋体" "" 0 1 0 "" "" "")
  17.   )
  18.   ;;;检查是否存在高程点图块定义
  19.   (if (not (tblobjname "block" "GC200"))
  20.     (progn
  21.       (setq blkdef (vla-Add (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-3D-point '(0 0 0)) "GC200"))
  22.       (setq obj
  23.         (vla-AddPolyline
  24.            blkdef
  25.            (vlax-make-variant
  26.               (vlax-safearray-fill
  27.                  (vlax-make-safearray vlax-vbdouble (cons 0 5))
  28.                  '(-0.2 0 0 0.2 0 0)
  29.               )
  30.            )
  31.         )
  32.       )
  33.       (vla-SetBulge obj 0 1) (vla-SetBulge obj 1 1)
  34.       (vla-put-Closed obj :vlax-true)
  35.       (vla-put-ConstantWidth obj 0.4)
  36.     )
  37.   )
  38.   ;;;插入块
  39.   (entmake (list
  40.              '(0 . "INSERT")
  41.              '(100 . "AcDbEntity")
  42.              '(100 . "AcDbBlockReference")
  43.              '(66 . 1);;;属性跟随标志,1跟随,0不跟随
  44.               (cons 2 "GC200")
  45.               (cons 10 inspt)
  46.               (cons 41 scale)
  47.               (cons 42 scale)
  48.               (cons 43 scale)
  49.               (list -3 '("SOUTH" (1000 . "202101")))
  50.            )
  51.   )
  52.   ;;;插入属性
  53.   (entmake (list
  54.              '(0 . "ATTRIB")
  55.              '(100 . "AcDbEntity")
  56.              '(100 . "AcDbText")
  57.               (cons 10 (setq pt (polar inspt 0 (* 1.2 scale))))
  58.               (cons 40 (* 2.0 scale))
  59.               (cons 50 0)
  60.               (cons 41 0.8)
  61.               (cons 51 0)
  62.               (cons 1 height)
  63.               (cons 7 "宋体")
  64.        (cons 62 3)
  65.               (cons 72 0)
  66.               (cons 11 pt)
  67.               '(100 . "AcDbAttribute")
  68.               (cons 2 "height")
  69.               (cons 70  0)
  70.               (cons 74 2)
  71.            )
  72.    )
  73.    ;;;结束标志
  74.    (entmake '((0 . "SEQEND")))
  75.    (princ)
  76. )
  77. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  78. (defun insertgc ( e / e)
  79.   (cdr(assoc 10(entget e)))
  80.   )
  81. (defun insertgc11 ( e / e)
  82.   (cdr(assoc 11(entget e)))
  83.   )

  84. (defun insert1 ( e / e)
  85.   (distof (cdr(assoc 1(entget e))) 2 )
  86.   )
  87. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  88. ( defun c:bgc ( /  blc scale wz height zb xzb zdzb)


  89. (setq blc (getint "\n请输入比例尺1:<500>"))
  90.   (if (= blc nil)(setq blc 500))
  91.   (setvar 'userr1 blc);设置比例尺
  92. (setq scale (* 0.001 blc));缩放比例

  93.   (while (setq wz(car(entsel "\n请选择要转换成高程点的数字文字text:")))

  94.   (setq height (insert1 wz))
  95.     (setq zb (insertgc wz))

  96.     (setq xzb (list  (+ (car zb) 1.1661) (- (cadr zb) 0.8044) height
  97.     )
  98.     );;;;;;
  99.    ;(setq zdzb (getpoint "\n请指定要标注高程点的位置:"))
  100.     ;(setq xzb  (list (car zdzb) (cadr zdzb)  height  ))
  101. (gxl-cs:gcd xzb height scale)
  102.    
  103.    )


  104. )

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

本版积分规则

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

GMT+8, 2024-4-26 12:56 , Processed in 0.227998 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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