AutoLisp 尝试选择 LWPolyline 但仅选择矩形.我怎么做? [英] AutoLisp trying to select LWPolyline BUT ONLY RECTANGLES. How do I do that?

查看:19
本文介绍了AutoLisp 尝试选择 LWPolyline 但仅选择矩形.我怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图选择所有矩形实体.我试过这个 (setq ss (ssget "X" '((0 . "RECTANG")))) ,但它似乎选择了所有多段线,包括多边形.我尝试检查顶点 = 4 但它也选择了钻石.我怎么能实现这样的代码?

So I'm trying to select all entities that are rectangles. I tried this (setq ss (ssget "X" '((0 . "RECTANG")))) , but it seems to select all polylines, including polygons. I tried with checking the vertices = 4 but then it also selects diamonds. How could I implement such a code?

推荐答案

如果您当前的代码使用了 ssget 过滤器列表 '((0 . "RECTANG")) 是选择任何东西,因为 RECTANG 不是 DXF 组 0 的有效实体类型.

I'd be highly surprised if your current code using the ssget filter list '((0 . "RECTANG")) was to select anything at all, as RECTANG is not a valid entity type for DXF group 0.

在 AutoCAD 中,标准的 RECTANG 命令实际上创建了 2D 多段线,其实体类型(DXF 组 0)为 LWPOLYLINE.因此,您的 ssget 过滤器列表应该开始:

In AutoCAD, the standard RECTANG command actually creates 2D polylines, whose entity type (DXF group 0) is LWPOLYLINE. As such, your ssget filter list should start:

(ssget "_X" '((0 . "LWPOLYLINE")))

我们可以使用以下方法进一步过滤此选择以仅选择具有 4 个顶点的 2D 折线:

We can filter this selection further to select only 2D polylines with 4 vertices using:

(ssget "_X" '((0 . "LWPOLYLINE") (90 . 4)))

我们可以使用以下方法过滤具有 4 个顶点的闭合折线:

And we can filter for closed polylines with 4 vertices using:

(ssget "_X" '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1)))

但是,仅使用 ssget 过滤器列表无法进一步缩小选择范围,因此要专门针对矩形,您需要遍历由以上表达式并删除所有非矩形的折线.

However, it is not possible to narrow the selection any further than this using only the ssget filter list, and so to target rectangles specifically, you'll need to iterate over the selection returned by the above expression and remove any polylines which are not rectangular.

您可以按以下方式编写这样的函数:

You might write such a function in the following way:

(defun selrectang ( / a b c d e i s )
    (if (setq s (ssget "_X" '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1))))
        (progn
            (repeat (setq i (sslength s))
                (setq i (1- i)
                      e (ssname s i)
                )
                (mapcar 'set '(a b c d) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget e))))
                (if
                    (not
                        (and
                            (equal (distance a b) (distance c d) 1e-8)
                            (equal (distance b c) (distance a d) 1e-8)
                            (equal (distance a c) (distance b d) 1e-8)
                        )
                    )
                    (ssdel e s)
                )
            )
            (if (< 0 (sslength s)) s)
        )
    )
)

这篇关于AutoLisp 尝试选择 LWPolyline 但仅选择矩形.我怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆