选择特定实体类型AutoLisp

问题描述 投票:0回答:2

选择一个点时,有一种方法可以过滤OSNAP,只捕捉到特定的实体类型,而不是另一种类型的实体。例如

仅捕捉线条。

setq startpt (*SNAP FILTER CODE* "LINE" (getpoint "\nChoose Start Line : "))

仅捕捉到弧线。

setq startpt (*SNAP FILTER CODE* "ARC" (getpoint "\nChoose Start Arc: "))

仅捕捉到折线。

setq startpt (*SNAP FILTER CODE* "POLYLINE" (getpoint "\nChoose Start Polyline: "))

我希望上面的假lisp有助于理解我想要问的内容。

提前致谢。

lisp autocad autocad-plugin autolisp
2个回答
2
投票

AutoLISP osnap函数可用于使用提供的“对象捕捉”修改器返回捕捉到几何体的点,但是,此函数不会过滤候选几何体。

因此,您可以选择提供getpoint返回的点作为过滤的ssget选择的点参数,或者测试nentselp函数返回的实体。

以下是使用ssget的可能解决方案:

(defun c:test1 ( / pnt )
    (while
        (and
            (setq pnt (getpoint "\nSelect start point on arc: "))
            (not (ssget pnt '((0 . "ARC"))))
        )
        (princ "\nThe point does not lie on an arc.")
    )
    (if pnt
        (princ (strcat "\nThe user picked (" (apply 'strcat (mapcar 'rtos pnt)) ")."))
        (princ "\nThe user did not supply a point.")
    )
    (princ)
)

以下是使用nentselp的可能解决方案:

(defun c:test2 ( / ent pnt )
    (while
        (and (setq pnt (getpoint "\nSelect start point on arc: "))
            (not
                (and
                    (setq ent (car (nentselp pnt)))
                    (= "ARC" (cdr (assoc 0 (entget ent))))
                )
            )
        )
        (princ "\nThe point does not lie on an arc.")
    )
    (if pnt
        (princ (strcat "\nThe user picked (" (apply 'strcat (mapcar 'rtos pnt)) ")."))
        (princ "\nThe user did not supply a point.")
    )
    (princ)
)

0
投票

可以处理这个问题,但它非常复杂。我可以告诉你,你可以使用函数(grread)来获取用户输入(鼠标移动或键盘按下)。然后你必须分析返回值,考虑osnaps。在这里你可以像这样过滤:

(cond 
        ( ( = (vlax-get-property curve 'ObjectName ) "AcDbMLeader" ) ( progn
            ...
        ) )
        (  ( = (vlax-get-property curve 'ObjectName ) "AcDbPolyline"  ) ( progn
            ...
        ) )
        ( YOUR NEXT CASES ( progn
            ...
        ) )
        ( t  (progn
            (princ "\n*Error:NotImplementedYetForThisEntity\n" ) )
        ) )
    )

你必须绘制你自己的osnap标记(形状绘制,例如基于系统变量(grvecs) "VIEWSIZE""SCREENSIZE"大小绘制。你需要处理极性跟踪,正交模式,按键盘上的按键。我曾经尝试过这样做,没有'处理每个案例,我的代码是几百行代码。抱歉,但我无法共享所有代码。

因此,如果您是AutoLISP的初学者,可能需要花费数周的时间才能解决问题。因此,请考虑您是否可以在此问题上花费这么多时间。也许您遇到的问题可能会以过滤osnaps的方式处理。

© www.soinside.com 2019 - 2024. All rights reserved.