明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2113|回复: 6

[源码] [gl]由多段线和标高值作地面线

[复制链接]
发表于 2016-3-16 15:20 | 显示全部楼层 |阅读模式
最近有张图纸需要根据等高线画剖断面的地面线。
作了一堆的辅助线,画起来相当烦躁,一地鸡毛。
想找LSP插件,没有找到。
于是抽空写了一个小程序,比较简陋,权当博君一笑。

本帖子中包含更多资源

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

x
 楼主| 发表于 2016-3-16 15:21 | 显示全部楼层
本帖最后由 brbright 于 2016-3-16 15:26 编辑
  1. ;;;===由多段线和标高值作地面线===

  2. ;;;说明:
  3. ;;;选择多段线和文字,匹配文字中的标高数值
  4. ;;;匹配原则是顶点到文字插入点(InsertionPoint)最近
  5. ;;;从多段线的起点开始,从左到右作地面线
  6. ;;;X坐标增量取两顶点间的直线距离
  7. ;;;Y坐标增量取文字中的标高差值
  8. (vl-load-com)
  9. (defun c:gl (/                           SPC
  10.              TX_ENT                   TX_TEXT
  11.              T_1                   T_ENT
  12.              T_ENTSEL                   T_GROUND_LINE_VERTICES
  13.              T_GROUND_STARTPOINT   T_HEIGHT_INCREMENT
  14.              T_NEAREST_TEXT           T_POINT_X
  15.              T_POINT_Y                   T_POINT_Y_G
  16.              T_POLYLINE_VERTICES   T_POLYLINE_VERTICES_NUM
  17.              T_SEGMENT_LENGTH_LIST T_SSFILTER
  18.              T_SSGET                   T_STARTPOINT_HEIGHT
  19.              T_TEXT_LIST           T_VERTICES-TEXT_LIST
  20.              T_VERTICES-TEXT_LIST_INCREMENT
  21.              T_VERTICES_LIST           T_VLA_VERTICES
  22.             )
  23.   ;;选择多段线
  24.   (setq t_entsel (entsel "选择多段线,然后选择单行文字(标高数字):"))
  25.   ;;选择文字
  26.   (setq        t_ssfilter
  27.          '((-4 . "<OR")
  28.            (0 . "TEXT")
  29.            (0 . "MTEXT")
  30.            (-4 . "OR>")
  31.           )
  32.   )
  33.   (setq t_ssget (ssget t_ssfilter))
  34.   ;;取得多段线、vla
  35.   (setq t_ent (car t_entsel))
  36.   (setq tx_ent (vlax-ename->vla-object t_ent))
  37.   ;;取得多段线顶点表
  38.   (setq        t_polyline_vertices
  39.          (vlax-safearray->list
  40.            (vlax-variant-value
  41.              (vlax-get-property tx_ent 'Coordinates)
  42.            )
  43.          )
  44.   )

  45.   ;;计算多段线顶点的数量
  46.   (setq t_polyline_vertices_num (/ (length t_polyline_vertices) 2))
  47.   ;;获取顶点表
  48.   (setq t_vertices_list (list))
  49.   (setq t_1 0)
  50.   (repeat t_polyline_vertices_num
  51.     (setq t_vertices_list
  52.            (cons
  53.              (list (nth (* t_1 2) t_polyline_vertices)
  54.                    (nth (+ 1 (* t_1 2)) t_polyline_vertices)
  55.              )
  56.              t_vertices_list
  57.            )
  58.     )
  59.     (setq t_1 (1+ t_1))
  60.   )
  61.   (setq t_vertices_list (reverse t_vertices_list))
  62.   ;;计算各多段线的线段长度表
  63.   (setq t_segment_length_list (list))
  64.   (setq t_1 0)
  65.   (repeat (1- t_polyline_vertices_num)
  66.     (setq t_segment_length_list
  67.            (cons (distance
  68.                    (nth t_1 t_vertices_list)
  69.                    (nth (1+ t_1) t_vertices_list)

  70.                  )
  71.                  t_segment_length_list
  72.            )
  73.     )
  74.     (setq t_1 (1+ t_1))
  75.   )
  76.   (setq t_segment_length_list (reverse t_segment_length_list))
  77.   ;;取得单行文字插入点数值及标高数值
  78.   (setq t_1 0)
  79.   (setq t_text_list (list))
  80.   (repeat (sslength t_ssget)
  81.     (setq tx_text (vlax-ename->vla-object (ssname t_ssget t_1)))
  82.     (setq t_text_list
  83.            (cons
  84.              (list (vlax-safearray->list
  85.                      (vlax-variant-value (vla-get-InsertionPoint tx_text))
  86.                    )
  87.                    (atof (vla-get-TextString tx_text))
  88.              )
  89.              t_text_list
  90.            )
  91.     )
  92.     (setq t_1 (1+ t_1))
  93.   )
  94.   (reverse t_text_list)
  95.   ;;按最近点原则为多段线顶点分配标高值
  96.   (setq t_vertices-text_list (list))
  97.   (foreach eachItem t_vertices_list
  98.     (setq t_nearest_text
  99.            (cdr        (car (vl-sort
  100.                        t_text_list
  101.                        '(lambda        (s1 s2)
  102.                           (<
  103.                             (distance
  104.                               (car s1)
  105.                               eachItem
  106.                             )
  107.                             (distance
  108.                               (car s2)
  109.                               eachItem
  110.                             )
  111.                           )
  112.                         )
  113.                      )
  114.                 )
  115.            )
  116.     )
  117.     (setq t_vertices-text_list
  118.            (cons
  119.              (append (list eachItem) t_nearest_text)
  120.              t_vertices-text_list
  121.            )
  122.     )
  123.   )
  124.   (setq t_vertices-text_list (reverse t_vertices-text_list))
  125.   ;;计算每一个标高值对多段线顶点标高值的差值
  126.   (setq t_vertices-text_list_increment (list))
  127.   (setq t_startpoint_height (cadr (car t_vertices-text_list)))
  128.   (foreach eachItem t_vertices-text_list
  129.     (setq t_height_increment (- (cadr eachItem) t_startpoint_height))
  130.     (setq t_vertices-text_list_increment
  131.            (cons (list (car eachItem) t_height_increment)
  132.                  t_vertices-text_list_increment
  133.            )
  134.     )
  135.   )
  136.   (setq        t_vertices-text_list_increment
  137.          (reverse
  138.            t_vertices-text_list_increment
  139.          )
  140.   )
  141.   ;;构建地面线的多段线点表
  142.   (setq t_ground_line_vertices (list))
  143.   (setq t_ground_startpoint (car t_vertices_list))

  144.   (setq t_point_x (car t_ground_startpoint))
  145.   (setq t_point_y_g (cadr t_ground_startpoint))

  146.   (setq        t_ground_line_vertices
  147.          (append t_ground_line_vertices
  148.                  (list t_point_x t_point_y_g)
  149.          )
  150.   )
  151.   (setq t_1 1)
  152.   (repeat (1- t_polyline_vertices_num)
  153.     (setq t_point_x (+ t_point_x
  154.                        (nth (1- t_1) t_segment_length_list)
  155.                     )
  156.     )
  157.     (setq t_point_y (+ t_point_y_g
  158.                        (cadr (nth t_1 t_vertices-text_list_increment))
  159.                     )
  160.     )
  161.     (setq t_ground_line_vertices
  162.            (append t_ground_line_vertices
  163.                    (list t_point_x t_point_y)
  164.            )
  165.     )
  166.     (print t_ground_line_vertices)
  167.     (setq t_1 (1+ t_1))
  168.   )
  169.   ;;将地面线顶点表转换为vlisp能处理数据表
  170.   (setq        t_vla_vertices
  171.          (vlax-make-safearray
  172.            vlax-vbDouble
  173.            (cons 0 (1- (length t_ground_line_vertices)))
  174.          )
  175.   )
  176.   (vlax-safearray-fill t_vla_vertices t_ground_line_vertices)
  177.   ;;更新多段线顶点
  178.   (LM:activespace 'doc 'spc)
  179.   (vla-AddLightWeightPolyline
  180.     spc
  181.     t_vla_vertices
  182.   )
  183.   (princ)
  184. )

  185. ;; Active Space  -  Lee Mac
  186. ;; Retrieves pointers to the Active Document and Space.
  187. ;; *doc - quoted symbol (other than *doc)
  188. ;; *spc - quoted symbol (other than *spc)
  189. (defun LM:activespace (*doc *spc)
  190.   (set *doc (vla-get-activedocument (vlax-get-acad-object)))
  191.   (set *spc
  192.        (vlax-get-property
  193.          (eval *doc)
  194.          (if (= 1 (getvar 'cvport))
  195.            'paperspace
  196.            'modelspace
  197.          )
  198.        )
  199.   )
  200.   nil
  201. )
  202. (princ)
发表于 2016-3-16 15:47 | 显示全部楼层
占个座            
发表于 2019-3-13 00:37 | 显示全部楼层
谢谢! brbright 分享程序!!!!
发表于 2020-7-11 12:50 | 显示全部楼层
好像只根据起点、终点数据生成的,中间数据没用,不知道怎么回事
发表于 2020-7-27 09:48 | 显示全部楼层
这个是例图,不知道怎么回事,没反应,求大神帮忙看一下

本帖子中包含更多资源

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

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

本版积分规则

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

GMT+8, 2024-5-18 16:06 , Processed in 0.161778 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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