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

查看:73
本文介绍了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天全站免登陆