隐藏隔离对象代码,感谢Gu_xl超级版主!
本帖最后由 flyfox1047 于 2013-11-13 12:50 编辑此LISP代码可以隐藏选择到的对象,想求一段类似于CAD2012里的“隔离对象”功能的LISP,就是隐藏选择以外的对象,作为YC4
望大神们帮忙完善,谢谢!
;YC1:隐藏选中的对象 ;YC2:隐藏同一颜色的对象 ;YC3:只显示选择颜色的对象 ;XS:显示所有隐藏的对象
(defun c:yc1 (/ ss ssn n)
(princ "\n请选择需要隐藏的对象:")
(setq ss (ssget))
(command "undo" "be")
(setvar "cmdecho" 0)
(setq n 0)
(while (< n (sslength ss))
(setq ssn (ssname ss n))
(setq ssn (entget ssn))
(setq ssn (append ssn '((60 . 1))))
;(setq ssn (cons '(60 . 1) ssn))
(entmod ssn)
(setq n (1+ n))
)
(command "undo" "e")
(princ)
)
(defun c:yc2 (/ ss ssn n cor m ss1 pd ssm)
(princ "\n请选择需要隐藏的颜色:")
(setq ss (nth 0 (entsel)))
(command "undo" "be")
(setvar "cmdecho" 0)
(setq cor (assoc 62 (entget ss))) ;颜色如果随层,按图层颜色
(if (= cor nil)
(progn (setq tc (cdr (assoc 8 (entget ss))))
(setq tc (tblsearch "layer" tc))
(setq cor (assoc 62 tc))
)
)
;;;找出不是随层符合颜色的对象
(setq ss (ssget "x" (list cor)))
(if (/= ss nil)
(progn (setq n 0)
(while (< n (sslength ss))
(setq ssn (ssname ss n))
(setq ssn (entget ssn))
(setq ssn (append ssn '((60 . 1))))
(entmod ssn)
(setq n (1+ n))
)
)
)
;;;找出随层符合颜色的对象
(setq tc (tblnext "layer" "0"))
(while (/= tc nil)
(if (equal cor (assoc 62 tc))
(progn (setq ss1 (ssget "x" (list (cons 8 (cdr (assoc 2 tc))))))
(if (/= ss1 nil)
(progn (setq m 0)
(while (< m (sslength ss1))
(setq ssm (entget (ssname ss1 m)))
(setq pd (assoc 62 ssm))
(if (= pd nil)
(progn (setq ssm (append ssm '((60 . 1)))) ;
(setq ssm (cons '(60 . 1) ssm))
(entmod ssm)
)
)
(setq m (1+ m))
)
)
)
)
)
(setq tc (tblnext "layer"))
)
(command "undo" "e")
(princ)
)
(defun c:yc3 (/ corss ssn cor ss corl n tc)
(princ "\n请选择不隐藏颜色:")
(setq ss (ssget))
(command "undo" "be")
(setvar "cmdecho" 0)
(setq corss (list))
(setq n 0)
(while (< n (sslength ss)) ;找出不关闭的颜色
(setq ssn (ssname ss n))
(setq cor (assoc 62 (entget ssn))) ;不随层
(if (= cor nil) ;随层
(progn (setq tc (cdr (assoc 8 (entget ssn))))
(setq tc (tblsearch "layer" tc))
(setq cor (assoc 62 tc))
)
)
(setq cor (cdr cor)) ;得到颜色
(setq corl (list cor))
(if (= nil (assoc cor corss))
(setq corss (cons corl corss))
)
(setq n (1+ n))
)
(princ "\n不隐藏颜色:")
(princ corss)
(setq ss (ssget "x" '()))
(setq n 0)
(while (< n (sslength ss))
(setq ssn (ssname ss n))
(setq cor (assoc 62 (entget ssn)))
(if (= cor nil)
(progn (setq tc (cdr (assoc 8 (entget ssn))))
(setq tc (tblsearch "layer" tc))
(setq cor (assoc 62 tc))
)
)
(setq cor (cdr cor)) ;得到颜色
(if (= nil (assoc cor corss)) ;如果不在表内隐藏
(progn (setq ssn (entget ssn))
(setq ssn (append ssn '((60 . 1))))
(entmod ssn)
)
)
(setq n (1+ n))
)
(command "undo" "e")
(princ)
)
(defun c:xs (/ ss ssn n)
(setq ss (ssget "x" (list (cons 60 1))))
(command "undo" "be")
(setvar "cmdecho" 0)
(setq n 0)
(while (< n (sslength ss))
(setq ssn (ssname ss n))
(setq ssn (entget ssn))
(setq ssn (subst (cons 60 0) (assoc 60 ssn) ssn))
(entmod ssn)
(setq n (1+ n))
)
(command "undo" "e")
)
;;隐藏选择对象 By Gu_xl
(defun c:yc ()
(if (ssget)
(progn
(vlax-for obj
(vla-get-activeselectionset
(vla-get-activedocument (vlax-get-acad-object))
)
(vla-put-Visible obj :vlax-false)
)
)
)
(princ)
)
;;隔离选择对象 By Gu_xl
(defun c:gl (/ ss ss1)
(if (setq ss (ssget))
(progn
(setq ss1 (ssget "x"))
(command "_select" ss1 "r" ss "")
(vlax-for obj
(vla-get-activeselectionset
(vla-get-activedocument (vlax-get-acad-object))
)
(vla-put-Visible obj :vlax-false)
)
)
)
(princ)
)
;;恢复显示 By Gu_xl
(defun c:hfxs (/ ss)
(if (setq ss (ssget "x" '((60 . 1))))
(vlax-for obj
(vla-get-activeselectionset
(vla-get-activedocument (vlax-get-acad-object))
)
(vla-put-Visible obj :vlax-true)
)
)
(princ)
)
flyfox1047 发表于 2013-11-12 14:13
版主,谢谢你的帮助,可是我试一下不行啊,显示 错误: no function definition: XYP-SUBUPD
版主,谢谢你的帮助,可是我试一下不行g啊,显示 错误: no function definition: XYP-SUBUPDt flyfox1047 发表于 2013-11-12 14:13
版主,谢谢你的帮助,可是我试一下不行啊,显示 错误: no function definition: XYP-SUBUPD
版主,谢谢你的帮助,可是我试一下不行啊,显示 错误: no function definition: XYP-SUBUPD
(defun c:yc4 ()
(princ "\n请选择需要隔离的对象: ")
(setq ss(ssget)
ss1 (ssget "x")
)
(command "select" ss1 "r" ss "")
(xyp-SubUpd (ssget "p") 60 1)
(princ)
) yc2在我这里没反应 xyp1964 发表于 2013-11-12 13:22 static/image/common/back.gif
版主,谢谢你的帮助,可是我试一下不行啊,显示 错误: no function definition: XYP-SUBUPD hao3ren 发表于 2013-11-12 13:55 static/image/common/back.gif
yc2在我这里没反应
YC2是隐藏同种颜色的对象 是的,但是没反应,没有隐藏掉 院长的简洁,好用,呵呵,装个xcad很方便 emk 发表于 2013-11-12 15:35 static/image/common/back.gif
院长的简洁,好用,呵呵,装个xcad很方便
可以XCAD其它功能用不上啊
yc2在我这里没反应,选择了,但是没显示出来。 没有高手帮忙啊