[原创]带提示和过滤表的entsel
功能:类似于(entsel)函数,带提示,且带一个过滤表,只选择表中类型例子:(sel '("LINE" "LWPOLYLINE") "选择直线...")
返回:同(entsel)一样,(对象名 选择点)
(defun Sel (_types msg / gr ent m ty)
(defun com(ty tylst / i rVal)
(setq i 0)
(while (< i (length tylst))
(if (= ty (nth i tylst))
(progn (setq rVal t) (setq i (length tylst)))
)
(setq i (1+ i))
)
rVal
)
(prompt msg)
(setq m nil)
(while (not m)
(setq gr (grread 2 4 2))
(cond
((= (car gr) 3)
(setq ent (ssget (cadr gr)))
(if (not (and ent (com (cdr (assoc 0 (entget (setq ent (ssnameent 0))))) _types)))
(setq ent nil)
)
(setq m t)
)
((= (car gr) 25) (setq m t))
)
)
(princ "\n")
(if ent (list ent (cadr gr)) nil)
)
本帖最后由 作者 于 2004-1-28 14:13:44 编辑
不用写那么多行;;(xentsel) = 带提示和过滤表的entsel (ssget "p" f)方法.精简代码!---------------------------------------------BY 无痕
;;调用:(XENTSEL "\n选择直线或圆..." '((0 . "*LINE,CIRCLE")))
;;循环选则直到选中符合过滤的实体为止(defun xentsel (msg filter)
(while (not (and (setq el (entsel msg)) (ssget "p" filter))))
el
);;调用:(XENTSEL1 "\n选择直线或圆..." '((0 . "*LINE,CIRCLE")))
;;只选一次,返回点表 (实体名 . 点位);选不中或空选返回nil.(defun xentsel1 (msg filter)
(if (and (setq el (entsel msg)) (ssget "p" filter)) el nil)
)
无痕 发表于 2004-1-24 05:59
不用写那么多行
精华在此 谢谢指路 這個應該做到, 如果選錯了要返回重新選嘛. 這樣就更好了 (entsel)选错了能返回重新选吗?我这个函数说了就是类似entsel的,不要总是挑这挑那,你也会编程,有要求为什么不自己写一个?
;;BY 龙龙仔(LUCAS)
;;USAGE:(ENTSEL_LAI "\n选择直线或圆..." '((0 . "*LINE,CIRCLE")))
(defun ENTSEL_LAI (MSG FILTER / SS SSS)
;;(while (not SS)
(setq SS (entsel MSG))
(if (/= SS NIL)
(progn
(command "_.SELECT" (car SS) "")
(if (not (setq SSS (ssget "P" FILTER)))
(setq SS NIL)
(list (ssname SSS 0) (cadr SS))
)
)
)
;;)
)
;;USAGE:(ENTSEL_MSG_FILTER "\n选取POLYINE对象: " '((0 . "LWPolyline")))
(defun ENTSEL_MSG_FILTER (MSG FILTER / SSPICK PICKOBJ PT1)
(prompt MSG)
(setq SSPICK (ssget ":S" FILTER))
(if SSPICK
(progn
(setq PICKOBJ (car (ssnamex SSPICK 0)))
(setq PT1 (cadr (nth 3 PICKOBJ)))
(list (nth 1 PICKOBJ) PT1)
)
)
)
程序不错!! xie xie 无痕发表于2004-1-24 5:59:00static/image/common/back.gif不用写那么多行
;;(xentsel) = 带提示和过滤表的entsel (ssget \"p\" f)方法.精简代码!---------------------------------------------BY 无痕
<FONT style="BACKGROUND-COLOR: #f3f3f3">无痕大侠,我在用xentsel函数时出了点问题</FONT>
<FONT style="BACKGROUND-COLOR: #f3f3f3">1.我用(setq p (xentsel "\n选择需修改的标注 :" '((0 . "DIMENSION"))))这句时,无法返回结果</FONT>
<FONT style="BACKGROUND-COLOR: #f3f3f3">2.我用(XENTSEL "\n选择直线或圆..." '((0 . "*LINE,CIRCLE")))选择标注时却可以返回标注的DXF</FONT>
据我分析应该是entsel选择后并不记录为“最近的选择集”,及“p”对其无效…… (defun XENTSEL (MSG FILTER)<BR> (while (not (and (setq EL (entsel MSG))<BR> (progn (command "_.select" (car EL) "")<BR> (ssget "p" FILTER)<BR> )<BR> )<BR> )<BR> )<BR> EL<BR>) (defun xentsel (msg filter)<BR> (while (not (and (setq el (entsel msg)) (ssget (cadr el) filter))))<BR> el<BR>)
页:
[1]
2