print1985
发表于 2012-6-10 19:53:35
本帖最后由 print1985 于 2012-6-10 20:10 编辑
先试试 暂时没加颜色隐藏
;[隐藏物体]
(defun c:yc (/ AcadObject AcadDocument LayersObj ss n i ent ob lay vlay lay-tn)
(setq AcadObject (vlax-get-acad-object)
AcadDocument (vla-get-ActiveDocument AcadObject)
LayersObj (vla-get-layers AcadDocument)
);end setq
(princ "\n请选择需要隐藏的物体" )
(if (setq ss (ssget))
(progn
(setq n (sslength ss))
(setq i (- n 1))
(repeat n
(setq ent (ssname ss i)
ob (vlax-ename->vla-object ent)
lay (vla-get-layer ob)
vlay (vla-item LayersObj lay)
);end setq
(if (= (setq lay-tn (vla-get-lock vlay)) :vlax-true);如果图层锁定
(vla-put-lock vlay :vlax-false);先解锁图层
);end if
(vla-put-visible ob :vlax-false)
(if (= lay-tn :vlax-true)
(vla-put-lock vlay :vlax-true);再锁定图层,恢复图层状态
);end if
(setq i (1- i))
);end repeat
(princ "\n已隐藏选择物体" )
));end if
(princ)
);end defun
;[恢复隐藏]
(defun c:xs (/ AcadObject AcadDocument LayersObj ss n i ent ob lay vlay lay-tn)
(setq AcadObject (vlax-get-acad-object)
AcadDocument (vla-get-ActiveDocument AcadObject)
LayersObj (vla-get-layers AcadDocument)
);end setq
(if (setq ss (ssget "x" '((60 . 1))))
(progn
(setq n (sslength ss))
(setq i (- n 1))
(repeat n
(setq ent (ssname ss i)
ob (vlax-ename->vla-object ent)
lay (vla-get-layer ob)
vlay (vla-item LayersObj lay)
);end setq
(if (= (setq lay-tn (vla-get-lock vlay)) :vlax-true)
(vla-put-lock vlay :vlax-false)
);end if
(vla-put-visible ob :vlax-true)
(if (= lay-tn :vlax-true)
(vla-put-lock vlay :vlax-true)
);end if
(setq i (1- i))
);end repeat
(princ "\n已显示隐藏物体" )
);end progn
(princ "\n本图无隐藏物体" )
);end if
;(vla-regen AcadDocument AcAllViewPorts) 图形较大有时需要重生成才显示 可把这句加上
(princ)
);end defun
;[隐藏物体(反)]
(defun c:yf (/ AcadObject AcadDocument LayersObj ssObj ss ob n i ent ob ss2 ss3 lay vlay lay-tn)
(setq AcadObject (vlax-get-acad-object)
AcadDocument (vla-get-ActiveDocument AcadObject)
LayersObj (vla-get-layers AcadDocument)
);end setq
(princ "\n请选择不需要隐藏的物体" )
(if (setq ss (ssget))
(progn
(setq ss2 (ssget "x" ))
(setq n (sslength ss))
(setq i (- n 1))
(repeat n
(setq ent (ssname ss i))
(if (setq ss3 (ssdel ent ss2))
(setq ss2 ss3)
);end if
(setq i (1- i))
);end repeat
(sssetfirst nil ss2)
(setq ssObj (vla-get-ActiveSelectionSet AcadDocument))
(vlax-for ob ssObj
(setq lay (vla-get-layer ob)
vlay (vla-item LayersObj lay)
);end setq
(if (= (setq lay-tn (vla-get-lock vlay)) :vlax-true)
(vla-put-lock vlay :vlax-false)
);end if
(vla-put-visible ob :vlax-false)
(if (= lay-tn :vlax-true)
(vla-put-lock vlay :vlax-true)
);end if
);end vlax-for
(princ "\n已隐藏非选择物体" )
));end if
(sssetfirst nil nil)
(princ)
);end defun
(princ "\n[隐藏物体-yc]/[恢复隐藏-xs]/[隐藏物体(反)-yf]" )
gzxl
发表于 2012-6-10 20:30:07
简短的
(defun ObjHidden ( / ssobj ent) ;隐藏对象物体
(if (setq ssobj (ssget))
(progn
(setq ssobj (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))
(vlax-for ent ssobj (vla-put-Visible ent :vlax-false))
)
)
(princ)
)
(defun RHidden ( / ssobj ent) ;恢复隐藏物体
(if (and (ssget "X" (list (cons 60 1) (cons 410 (getvar "CTAB"))))
(setq ssobj (ssget "X" (list (cons 410 (getvar "CTAB")))))
)
(progn
(setq ssobj (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))
(vlax-for ent ssobj (vla-put-Visible ent :vlax-true))
(prompt "\n显示所有物件!")
)
(prompt "\n无隐藏物件!")
)
(princ)
)
print1985
发表于 2012-6-10 20:42:39
gzxl 发表于 2012-6-10 20:30 static/image/common/back.gif
简短的
(defun ObjHidden ( / ssobj ent) ;隐藏对象物体
(if (setq ssobj (ssget))
你把图层锁定了试试,简短是要付出代价的
代码原理基本是相同的,我的代码增加了对锁定图层的处理
print1985
发表于 2012-6-10 20:50:45
请大家测试下,是否对某些特殊情况会出错,如果没问题了再加到主程序里面
gzxl
发表于 2012-6-10 21:05:42
print1985 发表于 2012-6-10 20:42 static/image/common/back.gif
你把图层锁定了试试,简短是要付出代价的
代码原理基本是相同的,我的代码增加了对锁定图层的处理
不然怎么叫简短
dalin1985
发表于 2012-6-10 21:14:27
学习一下,谢谢楼主。
yjr111
发表于 2012-6-10 22:20:04
关于隐藏物体的代码论坛已经比较多了,但有个缺点就是对隐藏物体的显示都是全显。。。
如果可以预览所隐藏的物体是不是更简便易用,更加人性化呢?希望楼主能先搞出来
longer1000
发表于 2012-6-11 08:45:16
好。支持源码.
print1985
发表于 2012-6-11 09:22:39
yjr111 发表于 2012-6-10 22:20 static/image/common/back.gif
关于隐藏物体的代码论坛已经比较多了,但有个缺点就是对隐藏物体的显示都是全显。。。
如果可以预览所隐藏 ...
预览?高级货啊,又是第一次听说,太孤陋寡闻了
详细说说呢,要达到什么样的预览效果,预览之后又需要些神马操作呢?
psdcdr
发表于 2012-6-11 09:24:13
print1985 发表于 2012-6-10 19:53 static/image/common/back.gif
先试试 暂时没加颜色隐藏
在2008下,出现错误,
命令: YC ; 错误: no function definition: VLAX-GET-ACAD-OBJECT
页:
1
[2]
3
4
5
6
7
8
9
10