Kowal 发表于 2022-7-5 20:02:23

[LISP]选择方向

你好
我使用ENTSEL函数选择LWPOLYLINE。
使用代码。
(setq cor (vlax-get (vlax-ename->vla-object (car (entsel))) 'coordinates))
总是得到。
'(1x 1y 2x 2y 3x 3y ...)
如何获得坐标列表,这取决于您选择的是哪一侧的多段线?
例子:
选择1-2侧的段。
 

 
获取:
'(1x 1y 2x 2y 3x 3y ...)
 
选择4-5侧的段。
 

 
获取:
'(5x 5y 4x 4y 3x 3y ...)

Tharwat 发表于 2022-7-5 20:13:39

试试这个。
 

(if (and (setq s (entsel "\n Pick a LWPOLYLINE :"))
      (eq (cdr (assoc 0 (entget (car s)))) "LWPOLYLINE")
      (mapcar '(lambda (p)
                   (if (eq (car p) 10)
                     (setq lst (cons (cdr p) lst))
                   )
               )
                (entget (setq o (car s)))
      )
   )
(if (< (distance (cadr s) (vlax-curve-getstartpoint o)) (distance (cadr s) (vlax-curve-getendpoint o)))
   (setq lst (reverse lst))
)
)

Lee Mac 发表于 2022-7-5 20:22:30

 
像这样的多段线呢?
(entmake
'(
       (000 . "LWPOLYLINE")
       (100 . "AcDbEntity")
       (100 . "AcDbPolyline")
       (90 . 5)
       (70 . 0)
       (10 0.0 0.0)
       (10 1.0 0.0)
       (10 1.0 1.0)
       (10 -0.01 1.0)
       (10 -0.01 -4.0)
   )
)

Lee Mac 发表于 2022-7-5 20:32:45

我会提出以下建议:
(defun c:test ( / e l s x )
   (if (and (setq s (entsel "\nSelect polyline: "))
            (= "LWPOLYLINE" (cdr (assoc 0 (setq x (entget (setq e (car s)))))))
            (setq l (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) x)))
       )
       (if (< (/ (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) 2.0)
            (vlax-curve-getdistatpoint e (vlax-curve-getclosestpointto e (trans (cadr s) 1 0)))
         )
         (reverse l) l
       )
   )
)
(vl-load-com) (princ)

Tharwat 发表于 2022-7-5 20:44:59

 
我打算使用vlax curve getdistatpoint函数,我不知道为什么我改变了主意,尽管我在之前的第一篇文章中的第一个代码应该按照OP的要求工作。
 
无论如何,这很容易处理,以涵盖其他形状的LWpolyline李的例子。
 

(defun c:Test (/ s o lst)
(if (and (setq s (entsel "\n Pick a LWPOLYLINE :"))
      (eq (cdr (assoc 0 (entget (setq o (car s))))) "LWPOLYLINE")
      (mapcar '(lambda (p)
                   (if (eq (car p) 10)
                     (setq lst (cons (cdr p) lst))
                   )
               )
                (entget o)
      )
   )
(if (> (vlax-curve-getdistatpoint o (vlax-curve-getclosestpointto o (cadr s)))
      (vlax-curve-getdistatparam o (vlax-curve-getendparam o))
   )
   (setq lst (reverse lst))
)
)
lst
)(vl-load-com)

Stefan BMR 发表于 2022-7-5 20:48:21

最近,我有完全相同的问题要解决。首先,我必须确定在哪里拾取多段线。
在这里看到李的代码后,我意识到我的代码在任何UCS/View上都不起作用。但是(trans p 1 0)也不能实现这一点。
这对任何情况都可能是一个有效的解决方案,但我让辩论开始,因为我不太确定。
(vlax-curve-getclosestpointtoprojection e (trans p 1 0) (trans (getvar 'viewdir) 1 0 T))

BIGAL 发表于 2022-7-5 20:55:29

我使用的一个简单方法是总是说“拾取开始-结束”。这里的想法是,如果你要这样做,就要说偏移量,你知道哪个是左偏移量,哪个是右偏移量,即使根据你的图像拾取的是上下偏移量。我能看到的唯一问题是,对于闭合样条线,您可能需要一个“再次拾取”选项,例如一个圆表示起点。

Kowal 发表于 2022-7-5 21:07:08

感谢您的回复。
页: [1]
查看完整版本: [LISP]选择方向