明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 5560|回复: 23

修改大神代码,横断面图转成高程点并导出

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

  74. ;;;;;;;;;;;;;;;;;;;;


  75. (defun c:tqdmsj()
  76.   (vl-load-com) ;将 Visual LISP 扩展功能加载到 AutoLISP
  77.      (setq blc (getint "\n请输入比例尺1:<500>"))
  78.   (if (= blc nil)(setq blc 500))
  79.   (setvar 'userr1 blc);设置比例尺
  80. (setq scale (* 0.001 blc));缩放比例
  81.   
  82.   (setq qszhxh (getint "\n请输入起始桩号-1后的序号:\n"))
  83. (srcs_data)
  84. (sjdc_data)
  85. (princ (strcat "\n文件写至" ffn))
  86. (prin1)
  87. )
  88. (defun srcs_data()
  89.   (setq ffn (getfiled "选取/建立数据导出文件" "" "hdm" 1))
  90.   (setq ff (open ffn "w"))
  91.   (close ff)
  92.   (setq hxbl (getint "\n请输入断面横向比例 1 :"))
  93.   (setq zxbl (getint "\n请输入断面纵向比例 1 :"))
  94. )
  95. (defun sjdc_data()
  96. (alert "请选择需要导出数据的断面线")
  97. (setq ss (ssget))
  98. (setq ii 0)
  99. (setq gcz 0.00)
  100. (repeat (sslength ss)
  101.     (setq ssn (ssname ss ii))
  102.     (setq endata (entget ssn))
  103.     (setq zh (getstring (strcat "\n请输入第" (rtos (1+ ii) 2 3) "个断面的桩号:")))
  104.     (if (= zh "") (setq zh (1+ ii)))
  105.     (setq qd (getpoint "\n请输入该断面中桩点的位置:"))
  106.       (setq qdx (car qd)) (setq qdy (cadr qd))
  107.     (setq bak gcz)
  108.     (setq gcz (getreal (strcat "\n请输入中桩点的高程:<" (rtos bak 2 3) ">")))
  109.       (if (= gcz nil) (setq gcz bak))
  110. (setq tmqd (getpoint "\n请输入该断面<平面图中>中桩点的位置:"))
  111.   (setq tmycfx (angle tmqd (getpoint "\n请输入该断面线<平面图中>右侧一点:") ))
  112.   
  113.     (setq ff (open ffn "a"))
  114.     (princ "begin," ff) (princ zh ff) (princ ":" ff) (princ (rtos (1+ qszhxh) 2 3) ff) (princ "\n" ff) (close ff)
  115.     (tqzb_data)
  116.     (setq ii (1+ ii)) (setq qszhxh (1+ qszhxh))
  117. )
  118. (prin1)
  119. )     

  120. (defun tqzb_data()
  121. (setq nn 0)
  122. (repeat (length endata)
  123.    (setq pp (nth nn endata))
  124.    (setq key (car pp))
  125.    (if (= key 10)
  126.        (progn
  127.           (setq xx (cadr pp)) (setq yy (caddr pp))
  128.           (setq dx (/ (- xx qdx) (/ 1000.000 hxbl)))
  129.           (setq dy (+ (/ (- yy qdy) (/ 1000.000 zxbl)) gcz) )
  130.    (setq xinzb (polar tmqd tmycfx dx))
  131.    (setq zxinzb (list (car xinzb) (cadr xinzb)  dy))
  132.    (gxl-cs:gcd  zxinzb dy scale)
  133.           (setq ff (open ffn "a"))
  134.           (princ (rtos dx 2 3) ff) (princ "," ff) (princ (rtos dy 2 3) ff) (princ "\n" ff)
  135.           (close ff)
  136.          )
  137.    )
  138.    (setq nn (1+ nn))
  139. )
  140. (prin1)
  141. )
  142. (prompt "提示:用<tqdmsj>命令来运行本程序")


本帖子中包含更多资源

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

x
发表于 2019-3-28 11:58 | 显示全部楼层
本帖最后由 wdjy808 于 2019-3-28 12:00 编辑

大神,我对你的这个插件进行了点简化,您输入的步骤有点多,现在只需要在C盘目录下,放一个文件(横断转点.dat)空白文件。不用去管横纵比例。
希望大神指正。
希望您加入批量转化功能

本帖子中包含更多资源

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

x
回复 支持 1 反对 0

使用道具 举报

发表于 2019-3-6 13:28 | 显示全部楼层
本帖最后由 skg123 于 2019-3-6 13:38 编辑

看了演示,没有测试。
建议:程序设计成不用在中线上指定位置绘图,应该设计出成 选好中线,后面的只要选择横断面线并输入横断面的里程,程序就自动在对应的中线上添加高程点,理由是点击中线上的位置,容易捕捉出错,对不是整桩的断面,找对应的位置很难,这个应该由程序推算精确的位置。免去往返中线与断面图这个动作,可提供效率。
发表于 2017-9-20 14:49 | 显示全部楼层
这个6了,gxl-cs:gcd这个被你用烂了
发表于 2017-9-21 08:30 | 显示全部楼层
厉害 能批量把hdm的地面线数据导出么!
 楼主| 发表于 2017-9-21 19:28 | 显示全部楼层
spp_wall 发表于 2017-9-21 08:30
厉害 能批量把hdm的地面线数据导出么!

你试试吧 应该可以
发表于 2017-9-24 14:37 | 显示全部楼层
不错,很不错的程序,
发表于 2017-9-25 22:02 | 显示全部楼层
很不错,谢谢!!!!
发表于 2017-10-15 10:35 | 显示全部楼层
树櫴希德 发表于 2017-9-21 19:28
你试试吧 应该可以

怎么显示字符串错误呢  老兄
发表于 2017-10-16 12:26 | 显示全部楼层
gxl-cs:gcd这个函数插入的高程点位Z值为0怎么破,高程值是正确的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-27 02:00 , Processed in 0.387736 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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