明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 858|回复: 8

[提问] 如何限定entsel从AutoCAD选定的图元类型

[复制链接]
发表于 2015-3-28 23:08 | 显示全部楼层 |阅读模式
假设用lisp编程时需要用entsel从AutoCAD界面选取一个矩形图元,请问怎样限制选取的图元对象只为矩形,而不能选定像圆或者多段线等其他类型的图元,谢谢指导。


该贴已经同步到 南林浣风的微博
发表于 2015-3-29 00:12 | 显示全部楼层
(defun isrectangle(e)
(if ...;;;自己写
    t nil)
)

(defun mysel()
  (while(not(isrectangle(car(setq en(entsel"选择矩形"))))))
en)
发表于 2015-3-29 00:17 | 显示全部楼层
矩形不是cad内置对象,恐怕可能(不确定)不能直接用组码选,所以先按多线段过滤选择,然后再通过条件判定是不是矩形!
发表于 2015-3-29 09:07 | 显示全部楼层
(while (not (and (setq s1 (entsel "\n选择矩形: "))
(setq ent (entget(car s1)))
(wcmatch (cdr(assoc 0 ent)) "*POLYLINE")
(= (cdr(assoc 90 ent)) 4)
(progn
(setq ptlst (list))
(foreach x ent (if (= (car x) 10) (setq ptlst (cons (cdr x) ptlst))))
(equal (distance (car ptlst) (caddr ptlst)) (distance (cadr ptlst) (last ptlst)) 1e-6)
)
)))
发表于 2015-3-29 09:12 | 显示全部楼层
ZZXXQQ 发表于 2015-3-29 09:07
(while (not (and (setq s1 (entsel "\n选择矩形: "))
(setq ent (entget(car s1)))
(wcmatch (cdr(ass ...

精辟的代码
发表于 2015-3-29 23:55 | 显示全部楼层
ZZXXQQ 发表于 2015-3-29 09:07
(while (not (and (setq s1 (entsel "\n选择矩形: "))
(setq ent (entget(car s1)))
(wcmatch (cdr(ass ...

对角线互相平分且相等的四边形是矩形
发表于 2015-3-30 00:03 | 显示全部楼层
有意义吗  
 楼主| 发表于 2015-4-2 01:18 | 显示全部楼层
ZZXXQQ 发表于 2015-3-29 09:07
(while (not (and (setq s1 (entsel "\n选择矩形: "))
(setq ent (entget(car s1)))
(wcmatch (cdr(ass ...

谢谢,非常感谢,但除了矩形,怎么限制其他类型的图元呢

点评

按规律判断。  发表于 2015-4-2 08:19
发表于 2015-4-2 16:13 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-19 15:52 , Processed in 0.321916 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表