phoenix2009 发表于 2022-7-5 19:53:21

测量多段之间的距离

大家好!
 
我喜欢测量多段线之间的距离,我找到了很好的visualLISP作为起点。此lisp使多段线之间的线可以测量。
 
但我有一些问题:
1.EX1中是新线直角,但“步骤50”是多段线1,我喜欢“步骤50”是多段线2,就像在EX2中一样,但在EX2中是新线角度错误。
很难解释:)
2、新线必须为红色
3、如何测量这些新线
 
感谢您提供的所有提示,或者可能已经有类似的提示了8)
 

 

;; written by Fatty T.O.H. ()2005 * all rights removed
;; edited 5/14/12
;; draw perpendicular lines
;;load ActiveX library
(vl-load-com)
;;local defuns

;;//
(defun start (curve)
(vl-catch-all-apply (function (lambda()
(vlax-curve-getclosestpointto curve
(vlax-curve-getstartpoint curve
   )
)
)
   )
)
)
;;//
(defun end (curve)
(vl-catch-all-apply (function (lambda()
(vlax-curve-getclosestpointto curve
(vlax-curve-getendpoint curve
   )
)
)
   )
)
)
;;//
(defun pointoncurve (curve pt)
(vl-catch-all-apply (function (lambda()
(vlax-curve-getclosestpointto curve
pt
   )
)
)
   )
)
;;//
(defun paramatpoint (curve pt)
(vl-catch-all-apply (function (lambda()
(vlax-curve-getparamatpoint curve
pt
   )
)
)
   )
)
;;//
(defun distatpt (curve pt)
(vl-catch-all-apply (function (lambda()
(vlax-curve-getdistatpoint curve
   (vlax-curve-getclosestpointto curve pt)
   )
)
   )
   )
)
;;//
(defun pointatdist (curve dist)
(vl-catch-all-apply (function (lambda()
(vlax-curve-getclosestpointto curve
(vlax-curve-getpointatdist curve dist)
   )
)
)
   )
)
;;//
(defun curvelength (curve)
(vl-catch-all-apply (function (lambda()
(vlax-curve-getdistatparam curve
(- (vlax-curve-getendparam curve)
    (vlax-curve-getstartparam curve)
   )
)
)
)
   )
)
;;//
(defun distatparam (curve param)
(vl-catch-all-apply (function (lambda()
(vlax-curve-getdistatparam curve
param
)
)
   )
   )
)
;;// written by VovKa (Vladimir Kleshev)
(defun gettangent (curve pt)

(setq param (paramatpoint curve pt)
       ang ((lambda (deriv)
    (if (zerop (cadr deriv))
      (/ pi 2)
      (atan (apply '/ deriv))
    )
)
   (cdr (reverse
   (vlax-curve-getfirstderiv curve param)
      )
   )
)
)
ang
)
;;// main program
;;--------------------------------------------------;;
(defun c:DIP (/ *error* acsp adoc cnt div en en2 ent ent2 ip lastp leng ln lnum mul num pt rot sign start step)

(defun *error* (msg)
   (vla-endundomark (vla-get-activedocument
             (vlax-get-acad-object))
      )
   (cond ((or (not msg)
       (member msg '("console break" "Function cancelled" "quit / exit abort"))
       )
   )
((princ (strcat "\nError: " msg)))
)

   (princ)
   )

(setq adoc (vla-get-activedocument (vlax-get-acad-object))
   acsp (vla-get-block (vla-get-activelayout adoc))
    )



(while (not
(and
    (or
      (initget 6)
      (setq step (getreal "\nEnter step <50>: "))
      (if (not step)
(setq step 50.)))
    ))
(alert "\nEnter a step")
)

(if (and
(setq
   ent (entsel
"\nSelect polyline 1 >>"
)
   )
(setq
   ent2 (entsel
"\nSelect polyline 2>>"
)
   )
)
(progn
    (setq en (car ent)
   pt (pointoncurve en (cadr ent))
   leng (distatparam en (vlax-curve-getendparam en))
   en2 (car ent2)
   )
    (setq num (fix (/ leng step))
   )
    (setq div (fix (/ 100. step)
   )
   )
    (setq mul (- leng
   (* (setq lnum (fix (/ leng (* step div)))) (* step div))))
    (if (not (zerop mul))
      (setq lastp T)
      (setq lastp nil)
      )
    (if (> (- (paramatpoint en pt)
       (paramatpoint en (vlax-curve-getstartpoint en))
       )
    (- (paramatpoint en (vlax-curve-getendpoint en))
       (paramatpoint en pt)
       )
    )
      (progn
(setq start leng
       sign-1
       )
)
      (progn
(setq start (distatparam en (vlax-curve-getstartparam en))
       sign1
       )
)
      )

    (vla-startundomark
      (vla-get-activedocument (vlax-get-acad-object))
      )
    (setq cnt 0)
    (repeat (1+ num)
      (setq pt(pointatdist en start)
   rot (gettangent en pt)
   )

(setq ln (vlax-invoke-method acsp 'addline (setq ip (vlax-3d-point pt))(vlax-3d-point(pointoncurve en2 pt))))
      (setq cnt   (1+ cnt)
   start (+ start (* sign step))
   )
      )

    (if lastp
      (progn
(if (= sign -1)
   (progn
   (setq pt(vlax-curve-getstartpoint en)
    rot (gettangent en pt)
    )
   )
   (progn
   (setq pt(vlax-curve-getendpoint en)
    rot (gettangent en pt)
    )
   )
   )
(setq ln (vlax-invoke-method acsp 'addline (setq ip (vlax-3d-point pt))(vlax-3d-point(pointoncurve en2 pt))))

)
      )

    )
(princ "\nNothing selected")
)
(*error* nil)
(princ)
)
(prompt "\n   >>>   Type DIP to execute...")
(prin1)
https://www.cadtutor.net/forum/images/misc_cadtutor/pencil.png

Tyke 发表于 2022-7-5 19:59:10

在示例1中,直线垂直于多段线2,在示例2中,直线垂直于多段线1。
 
看起来您需要考虑应该首先拾取哪个多段线。对于LISP例程来说,首先选择哪条线很重要。

phoenix2009 发表于 2022-7-5 20:01:18

感谢您的回复!
是的,你是对的。我喜欢示例1,这些线垂直于多段线2,但我需要“步骤50”也垂直于多段线2,而不是多段线1。这很难。

Tyke 发表于 2022-7-5 20:04:10

 
非常欢迎你。
 
步骤50是拾取的第一条多段线上的直线之间的距离,因此是两种不同的情况。不能在两条多段线上都有步骤50,因为从数学上讲这是不可能的。在我看来,可以做你想做的事情,但那需要重写LISP例程,很不幸我不是你要做的人。论坛上还有其他成员可以这样做。

phoenix2009 发表于 2022-7-5 20:09:11

无论如何谢谢你,小家伙!
我已经学习了一些visualLisp函数,并尝试自己修复它,但这对我来说太难了。对我来说,autoLisp函数要简单得多。如果有一些好人和聪明的成员,那么我非常感谢;)

irneb 发表于 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)))(而(

phoenix2009 发表于 2022-7-5 20:13:21

代码很好,但新行应该是垂直的红色。
感谢您的回复!

irneb 发表于 2022-7-5 20:17:40

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

phoenix2009 发表于 2022-7-5 20:19:58

我喜欢的是类似以下的东西:
新线垂直于多段线1,“步骤50”也在多段线1上,然后该线测量。
感谢您深入了解!

irneb 发表于 2022-7-5 20:22:04

我的意思是这样的事情应该怎么做?
页: [1] 2
查看完整版本: 测量多段之间的距离