乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 28|回复: 19

[编程交流] 测量多段之间的距离

[复制链接]

1

主题

9

帖子

8

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 19:53:21 | 显示全部楼层 |阅读模式
大家好!
 
我喜欢测量多段线之间的距离,我找到了很好的visualLISP作为起点。此lisp使多段线之间的线可以测量。
 
但我有一些问题:
1.EX1中是新线直角,但“步骤50”是多段线1,我喜欢“步骤50”是多段线2,就像在EX2中一样,但在EX2中是新线角度错误。
很难解释:)
2、新线必须为红色
3、如何测量这些新线
 
感谢您提供的所有提示,或者可能已经有类似的提示了8)
 
205321gonrjdnsjyo33jrw.jpg
 
  1. ;; written by Fatty T.O.H. ()2005 * all rights removed
  2. ;; edited 5/14/12
  3. ;; draw perpendicular lines
  4. ;;load ActiveX library
  5. (vl-load-com)
  6. ;;local defuns
  7. ;;//
  8. (defun start (curve)
  9. (vl-catch-all-apply (function (lambda()
  10. (vlax-curve-getclosestpointto curve
  11. (vlax-curve-getstartpoint curve
  12.    )
  13. )
  14. )
  15.    )
  16. )
  17. )
  18. ;;//
  19. (defun end (curve)
  20. (vl-catch-all-apply (function (lambda()
  21. (vlax-curve-getclosestpointto curve
  22. (vlax-curve-getendpoint curve
  23.    )
  24. )
  25. )
  26.    )
  27. )
  28. )
  29. ;;//
  30. (defun pointoncurve (curve pt)
  31. (vl-catch-all-apply (function (lambda()
  32. (vlax-curve-getclosestpointto curve
  33. pt
  34.    )
  35. )
  36. )
  37.    )
  38. )
  39. ;;//
  40. (defun paramatpoint (curve pt)
  41. (vl-catch-all-apply (function (lambda()
  42. (vlax-curve-getparamatpoint curve
  43. pt
  44.    )
  45. )
  46. )
  47.    )
  48. )
  49. ;;//
  50. (defun distatpt (curve pt)
  51. (vl-catch-all-apply (function (lambda()
  52. (vlax-curve-getdistatpoint curve
  53.    (vlax-curve-getclosestpointto curve pt)
  54.    )
  55. )
  56.    )
  57.    )
  58. )
  59. ;;//
  60. (defun pointatdist (curve dist)
  61. (vl-catch-all-apply (function (lambda()
  62. (vlax-curve-getclosestpointto curve
  63. (vlax-curve-getpointatdist curve dist)
  64.    )
  65. )
  66. )
  67.    )
  68. )
  69. ;;//
  70. (defun curvelength (curve)
  71. (vl-catch-all-apply (function (lambda()
  72. (vlax-curve-getdistatparam curve
  73. (- (vlax-curve-getendparam curve)
  74.     (vlax-curve-getstartparam curve)
  75.    )
  76. )
  77. )
  78. )
  79.    )
  80. )
  81. ;;//
  82. (defun distatparam (curve param)
  83. (vl-catch-all-apply (function (lambda()
  84. (vlax-curve-getdistatparam curve
  85. param
  86. )
  87. )
  88.    )
  89.    )
  90. )
  91. ;;// written by VovKa (Vladimir Kleshev)
  92. (defun gettangent (curve pt)
  93. (setq param (paramatpoint curve pt)
  94.        ang ((lambda (deriv)
  95.     (if (zerop (cadr deriv))
  96.       (/ pi 2)
  97.       (atan (apply '/ deriv))
  98.     )
  99.   )
  100.    (cdr (reverse
  101.    (vlax-curve-getfirstderiv curve param)
  102.         )
  103.    )
  104. )
  105. )
  106. ang
  107. )
  108. ;;// main program
  109. ;;--------------------------------------------------;;
  110. (defun c:DIP (/ *error* acsp adoc cnt div en en2 ent ent2 ip lastp leng ln lnum mul num pt rot sign start step)
  111. (defun *error* (msg)
  112.      (vla-endundomark (vla-get-activedocument
  113.              (vlax-get-acad-object))
  114.       )
  115.    (cond ((or (not msg)
  116.        (member msg '("console break" "Function cancelled" "quit / exit abort"))
  117.        )
  118.    )
  119.   ((princ (strcat "\nError: " msg)))
  120.   )
  121.    (princ)
  122.    )
  123. (setq adoc (vla-get-activedocument (vlax-get-acad-object))
  124.    acsp (vla-get-block (vla-get-activelayout adoc))
  125.     )
  126. (while (not
  127.   (and
  128.     (or
  129.       (initget 6)
  130.       (setq step (getreal "\nEnter step <50>: "))
  131.       (if (not step)
  132. (setq step 50.)))
  133.     ))
  134.   (alert "\nEnter a step")
  135.   )
  136. (if (and
  137. (setq
  138.    ent (entsel
  139.   "\nSelect polyline 1 >>"
  140.   )
  141.    )
  142. (setq
  143.    ent2 (entsel
  144.   "\nSelect polyline 2  >>"
  145.   )
  146.    )
  147. )
  148.   (progn
  149.     (setq en (car ent)
  150.    pt (pointoncurve en (cadr ent))
  151.    leng (distatparam en (vlax-curve-getendparam en))
  152.    en2 (car ent2)
  153.    )
  154.     (setq num (fix (/ leng step))
  155.    )
  156.     (setq div (fix (/ 100. step)
  157.      )
  158.    )
  159.     (setq mul (- leng
  160.    (* (setq lnum (fix (/ leng (* step div)))) (* step div))))
  161.     (if (not (zerop mul))
  162.       (setq lastp T)
  163.       (setq lastp nil)
  164.       )
  165.     (if (> (- (paramatpoint en pt)
  166.        (paramatpoint en (vlax-curve-getstartpoint en))
  167.        )
  168.     (- (paramatpoint en (vlax-curve-getendpoint en))
  169.        (paramatpoint en pt)
  170.        )
  171.     )
  172.       (progn
  173. (setq start leng
  174.        sign  -1
  175.        )
  176. )
  177.       (progn
  178. (setq start (distatparam en (vlax-curve-getstartparam en))
  179.        sign  1
  180.        )
  181. )
  182.       )
  183.     (vla-startundomark
  184.       (vla-get-activedocument (vlax-get-acad-object))
  185.       )
  186.     (setq cnt 0)
  187.     (repeat (1+ num)
  188.       (setq pt  (pointatdist en start)
  189.      rot (gettangent en pt)
  190.      )
  191. (setq ln (vlax-invoke-method acsp 'addline (setq ip (vlax-3d-point pt))(vlax-3d-point(pointoncurve en2 pt))))
  192.       (setq cnt   (1+ cnt)
  193.      start (+ start (* sign step))
  194.      )
  195.       )
  196.     (if lastp
  197.       (progn
  198. (if (= sign -1)
  199.    (progn
  200.      (setq pt  (vlax-curve-getstartpoint en)
  201.     rot (gettangent en pt)
  202.     )
  203.      )
  204.    (progn
  205.      (setq pt  (vlax-curve-getendpoint en)
  206.     rot (gettangent en pt)
  207.     )
  208.      )
  209.    )
  210. (setq ln (vlax-invoke-method acsp 'addline (setq ip (vlax-3d-point pt))(vlax-3d-point(pointoncurve en2 pt))))
  211. )
  212.       )
  213.     )
  214.   (princ "\nNothing selected")
  215.   )
  216. (*error* nil)
  217. (princ)
  218. )
  219. (prompt "\n   >>>   Type DIP to execute...")
  220. (prin1)

                               
登录/注册后可看大图
回复

使用道具 举报

29

主题

519

帖子

477

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-5 19:59:10 | 显示全部楼层
在示例1中,直线垂直于多段线2,在示例2中,直线垂直于多段线1。
 
看起来您需要考虑应该首先拾取哪个多段线。对于LISP例程来说,首先选择哪条线很重要。
回复

使用道具 举报

1

主题

9

帖子

8

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 20:01:18 | 显示全部楼层
感谢您的回复!
是的,你是对的。我喜欢示例1,这些线垂直于多段线2,但我需要“步骤50”也垂直于多段线2,而不是多段线1。这很难。
回复

使用道具 举报

29

主题

519

帖子

477

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-5 20:04:10 | 显示全部楼层
 
非常欢迎你。
 
步骤50是拾取的第一条多段线上的直线之间的距离,因此是两种不同的情况。不能在两条多段线上都有步骤50,因为从数学上讲这是不可能的。在我看来,可以做你想做的事情,但那需要重写LISP例程,很不幸我不是你要做的人。论坛上还有其他成员可以这样做。
回复

使用道具 举报

1

主题

9

帖子

8

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 20:09:11 | 显示全部楼层
无论如何谢谢你,小家伙!
我已经学习了一些visualLisp函数,并尝试自己修复它,但这对我来说太难了。对我来说,autoLisp函数要简单得多。如果有一些好人和聪明的成员,那么我非常感谢;)
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-5 20:10:21 | 显示全部楼层
如果您不介意将线与任何一条多段线进行非perp,那么这是可能的。也许可以试试这样:
(/dist poly1 poly2 dist1 len1 len2 getpoly2 corresponding clay)(或*distbetweenline*(setq*distbetweenline*50.0))(如果(和(或(setq dist(setdist)(strcat“\n线间多远:”)(setq dist*distbetweenline*)(setq poly1(entsel“\n点击第一定义多段线:”)(setq poly2(entsel“\n点击第二多段线:”))(progn(setq poly1(car poly1)poly2(car poly2)dist1 0.0 len1(vlax curve getDistAtParam poly1(vlax curve getEndParam poly1))len2(vlax curve getDistAtParam poly2(vlax curve getEndParam poly2))粘土(getvar“CLayer”);;检查多边形是否不是同向-交换方向(if(inters(vlax curve getPointAtParam poly1 0.0)(vlax curve getPointAtParam poly2 0.0)(vlax curve getPointAtParam poly1(vlax curve getEndParam poly1))(vlax curve getPointAtParam poly2(vlax curve getEndParam poly2))(defun getpoly2对应(d)(vlax curve getPointAtDist poly2(-len2(*(/dist1 len1)len2)))(defun getpoly2对应(d)(vlax curve getPointAtDist poly2(*(/dist1 len1)len2)))(而(
回复

使用道具 举报

1

主题

9

帖子

8

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 20:13:21 | 显示全部楼层
代码很好,但新行应该是垂直的红色。
感谢您的回复!
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-5 20:17:40 | 显示全部楼层
要使它们变成红色,请在entmake列表的某处添加一行,如“(62.1)。或者在运行代码之前简单地设置一个颜色=红色电流的层(这实际上是我的选择,因为我尽可能避免使用覆盖的颜色绘制-而是使用不同的层并保持按层着色)。 
至于垂直,你不可能得到你想要的。要么最终得到类似于EX2的东西(在某些情况下-注意,它可能发生在多段线2沿线的某个地方,也取决于其形状),要么最终得到相互交叉的线(我认为这不是您想要的)。在物理上不可能绘制垂直于一条多段线但在两条多段线之间等距的线。其中一条规则必须打破。
 
试着手动绘制,看看你是否能得到你想要的。如果可以,请将该DWG发布在此处,以便我们了解您所做的工作,并从中计算lisp。
回复

使用道具 举报

1

主题

9

帖子

8

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 20:19:58 | 显示全部楼层
我喜欢的是类似以下的东西:
新线垂直于多段线1,“步骤50”也在多段线1上,然后该线测量。
感谢您深入了解!
205324h5lmyhxy3gm99oh9.jpg
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-5 20:22:04 | 显示全部楼层
我的意思是这样的事情应该怎么做?
205325zw4p7y4t0x6z04x7.png
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 01:10 , Processed in 1.945914 second(s), 75 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表