明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 20901|回复: 137

请问为什么隐显对象对象有时行有时不行

  [复制链接]
发表于 2012-3-31 23:13:48 | 显示全部楼层 |阅读模式
1明经币
本帖最后由 flytoday 于 2012-3-31 23:17 编辑

(defun c:DOFF (/ ss)
(vl-load-com)
(prompt "\n 选择对象隐藏: ")
(if (setq ss (ssget))
((lambda (i / e)
(while (setq e (ssname ss (setq i (1+ i))))
(vla-put-visible
(vlax-ename->vla-object e)
:vlax-false)))
-1))
(princ))
;--------------------------------------------------
(defun c:DON (/ ss)
(vl-load-com)
(prompt "\n 所有的对象已打开... ")
(if (setq ss (ssget "_x"))
((lambda (i / e)
(while (setq e (ssname ss (setq i (1+ i))))
(vla-put-visible
(vlax-ename->vla-object e)
:vlax-true)))
-1))
(princ))
;---------------------对象的隐藏和取消隐藏-------------------



有时候隐藏是隐藏了就是显示不出来.....
有时有些对些对象不能隐藏了(天正的墙体之类的不能隐藏)
提示
; 错误: Automation 错误。未提供说明。
哪位大侠帮修改下..让程序适用天正及CAD所有对象都能隐藏显示///谢谢

最佳答案

查看完整内容

显示隐藏工具 **** 本内容被作者隐藏 ****

点评

失灵时不灵,那是段誉的六脉神剑!  发表于 2012-4-1 09:30
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2012-3-31 23:13:49 | 显示全部楼层
本帖最后由 Gu_xl 于 2012-4-1 12:00 编辑

显示隐藏工具
  1. ;;隐藏对象
  2. (defun c:Objhide  (/ ss n data) (vl-load-com)
  3.   (setq ss (ssget ":L"))
  4.   (if ss
  5.     (progn
  6.       (repeat (setq n (sslength ss))
  7.         (vla-put-Visible
  8.           (setq        obj (vlax-ename->vla-object
  9.                       (ssname ss (setq n (1- n)))))
  10.           :vlax-false)
  11.         (setq data (cons (vla-get-Handle obj) data))
  12.         )
  13.       (VLAX-LDATA-PUT
  14.         "隐藏对象"
  15.         "隐藏对象数据"
  16.         (append (VLAX-LDATA-get "隐藏对象" "隐藏对象数据") Data))
  17.       )
  18.     )
  19.   (princ)
  20.   )
  21. ;;显示对象
  22. (defun c:ObjShow  (/ data en LayerStaus layer layers)
  23.   (vl-load-com)
  24.   (setq data (VLAX-LDATA-get "隐藏对象" "隐藏对象数据"))
  25.   (if data
  26.     (progn
  27.       (foreach hand  data
  28.         (if (setq en (handent hand))
  29.           (progn
  30.             (setq layers (vla-get-layers
  31.                            (vla-get-ActiveDocument
  32.                              (vlax-get-acad-object))))
  33.             (if        (or (= :vlax-true
  34.                        (vla-get-Lock
  35.                          (setq
  36.                            layer (vla-item layers
  37.                                            (vla-get-layer
  38.                                              (setq obj
  39.                                                     (vlax-ename->vla-object
  40.                                                       en)))))))
  41.                     (= :vlax-true (vla-get-Freeze layer))
  42.                     )
  43.               (progn
  44.                 (setq LayerStaus
  45.                        (cons (list layer
  46.                                    (vla-get-Lock layer)
  47.                                    (vla-get-Freeze layer))
  48.                              LayerStaus)) ;_ 保存图层状态
  49.                 (vla-put-lock layer :vlax-false) ;_ 解锁
  50.                 (vla-put-lock layer :vlax-false) ;_ 解冻
  51.                 )
  52.               )

  53.             (vla-put-Visible obj :vlax-true) ;_ 显示
  54.             )
  55.           )
  56.         )
  57.       (VLAX-LDATA-delete "隐藏对象" "隐藏对象数据")
  58.       (if LayerStaus
  59.         (foreach la  LayerStaus
  60.           (vla-put-lock (car la) (cadr la))
  61.           (vla-put-freeze (car la) (caddr la))
  62.           )
  63.         )
  64.       )
  65.     )
  66.   (princ)
  67.   )

点评

看来G版已经修成金刚不坏神功,六脉神剑也轻易破解了  发表于 2012-4-1 12:40

评分

参与人数 1明经币 +1 收起 理由
flytoday + 1 很给力!G版出手超完美。。。谢谢。太感动了

查看全部评分

回复

使用道具 举报

发表于 2012-4-1 00:39:36 | 显示全部楼层
  1. ;;;---------------------------------------------------------------------------;
  2. ;;;
  3. ;;;   BLANK.LSP   Version 1.0
  4. ;;;
  5. ;;;   Copyright (C) 1995 by Autodesk, Inc.
  6. ;;;
  7. ;;;   Permission to use, copy, modify, and distribute this software and its
  8. ;;;   documentation for any purpose and without fee is hereby granted.
  9. ;;;
  10. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
  11. ;;;   ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
  12. ;;;   MERCHANTABILITY ARE HEREBY DISCLAIMED.
  13. ;;;
  14. ;;;---------------------------------------------------------------------------;
  15. ;;;   BLANK, UNBLANK, and UNBLANKALL
  16. ;;;
  17. ;;;   This module provides functions to manipulate the visibility field of
  18. ;;;   AutoCAD objects.  BLANK will make a selection set of objects invisible.
  19. ;;;   UNBLANK will make a specified object (given its handle) visible.
  20. ;;;   UNBLANKALL will make all blanked entities visible.
  21. ;;;
  22. ;;;---------------------------------------------------------------------------;


  23. ;;;---------------------------------------------------------------------------;
  24. ;;; Internal error handling.
  25. ;;;---------------------------------------------------------------------------;
  26. (defun blank_error(s)
  27.   ;; The strings in the following statements can be translated.
  28.   (if (/= s ;|MSG1|;"Function cancelled")
  29.     (princ (strcat ;|MSG2|;"\nBLANK Error: " s))
  30.   )
  31.   (setq *error* olderr)
  32.   (princ)
  33. )

  34. (defun unblank_error(s)
  35.   ;; The strings in the following statements can be translated.
  36.   (if (/= s ;|MSG3|;"Function cancelled")
  37.     (princ (strcat ;|MSG3|;"\nUNBLANK Error: " s))
  38.   )
  39.   (setq *error* olderr)
  40.   (princ)
  41. )

  42. (defun blank60 (e / e2)
  43.   (if (not (null (assoc '60 e)))
  44.     (setq e2 (subst '(60 . 1) '(60 . 0) e))
  45.     (setq e2 (append e '((60 . 1))))
  46.   )
  47. )   

  48. (defun show60 (e / e2)
  49.   (if (not (null (assoc '60 e)))
  50.      (setq e2 (subst '(60 . 0) '(60 . 1) e))
  51.      (setq e2 (append e '((60 . 0))))
  52.   )
  53. )

  54. (defun setvis ( vis ename / e)
  55.   (setq e (entget ename))
  56.   (if (eq vis 0)
  57.      (entmod (show60 e))
  58.      (entmod (blank60 e))
  59.   )
  60.   (entupd ename)
  61.   ;; Blank vertices of polyline, if necessary
  62.   (if (eq (cdr (nth 1 e)) "POLYLINE")
  63.     (progn
  64.       (setq ename (entnext ename))
  65.       (setq e (entget ename))
  66.       (while (eq (cdr (nth 1 e)) "VERTEX")
  67.         (if (eq vis 0)
  68.            (entmod (show60 e))
  69.            (entmod (blank60 e))
  70.         )
  71.         (entupd ename)
  72.         (setq ename (entnext ename))
  73.         (setq e (entget ename))
  74.       ) ; while
  75.     ) ; progn
  76.   ) ; if polyline
  77.   (if (and (eq (cdr (nth 1 e)) "INSERT")
  78.            (assoc '66 e))
  79.     (progn
  80.       (setq ename (entnext ename))
  81.       (setq e (entget ename))
  82.       (while (eq (cdr (nth 1 e)) "ATTRIB")
  83.         (if (eq vis 0)
  84.            (entmod (show60 e))
  85.            (entmod (blank60 e))
  86.         )
  87.         (entupd ename)
  88.         (setq ename (entnext ename))
  89.         (setq e (entget ename))
  90.       ) ; while
  91.     ) ; progn
  92.   )
  93. )

  94. (defun c:blank ( ) ;;; / olderr echo ss i ename )
  95.   (setq olderr *error*                ; Redefine error handler.
  96.         echo (getvar ;|MSG0|;"cmdecho")
  97.         *error* blank_error)
  98.   (setvar ;|MSG0|;"cmdecho" 0)                ; Turn off cmdecho sysvar
  99.   (command ;|MSG0|;"_.undo" ;|MSG0|;"_group")

  100.   (setq ss (ssget))
  101.   (setq i 0)
  102.   (while (< i (sslength ss)) (progn
  103.      (setq ename (ssname ss i))
  104.      (setvis 1 ename)
  105.      (setq i (1+ i))
  106.   ))

  107.   (setq *error* old_error)            ; restore error function
  108.   (command ;|MSG0|;"_.undo" ;|MSG0|;"_end")
  109.   (setvar ;|MSG0|;"cmdecho" echo)             ; restore cmdecho sysvar
  110.   (princ)                             ; Quiet exit.
  111. )

  112. (defun c:unblankall ( ) ;;; / olderr echo ss i ename )
  113.   (setq olderr *error*                ; Redefine error handler.
  114.         echo (getvar ;|MSG0|;"cmdecho")
  115.         *error* unblank_error)
  116.   (setvar ;|MSG0|;"cmdecho" 0)                ; Turn off cmdecho sysvar
  117.   (command ;|MSG0|;"_.undo" ;|MSG0|;"_group")

  118.   ;; Select all blanked entities
  119.   (setq ss (ssget ;|MSG0|;"_x" '((60 . 1))))
  120.   (if (not (null ss))
  121.     (progn
  122.       (setq i 0)
  123.       (princ (sslength ss))
  124.       (princ " blanked entities found.\n");
  125.       ;; Unblank each entity in the set
  126.       (while (< i (sslength ss)) (progn
  127.          (setq ename (ssname ss i))
  128.          (setvis 0 ename)
  129.          (setq i (1+ i))
  130.       ))
  131.     )   
  132.     (princ "\n0 blanked entities found.\n");
  133.   )

  134.   (setq *error* old_error)            ; restore error function
  135.   (command ;|MSG0|;"_.undo" ;|MSG0|;"_end")
  136.   (setvar ;|MSG0|;"cmdecho" echo)             ; restore cmdecho sysvar
  137.   (princ)                             ; Quiet exit.
  138. )

  139. (defun c:unblank ( ) ;;; / olderr echo ss i ename hand )
  140.   (setq olderr *error*                ; Redefine error handler.
  141.         echo (getvar ;|MSG0|;"cmdecho")
  142.         *error* unblank_error)
  143.   (setvar ;|MSG0|;"cmdecho" 0)                ; Turn off cmdecho sysvar
  144.   (command ;|MSG0|;"_.undo" ;|MSG0|;"_group")

  145.   (setq hand (getstring ;|MSG5|;"\nEnter handle of entity to be unblanked: "))
  146.   ;; Unblank the entity if handle is not an empty string
  147.   (if (> (strlen hand) 0)
  148.     (progn
  149.       (setq ename (handent hand))
  150.       (if (/= nil ename)
  151.         (setvis 0 ename)
  152.         (princ ;|MSG6|;"Invalid handle.")
  153.       )
  154.     )
  155.   )

  156.   (setq *error* old_error)            ; restore error function
  157.   (command ;|MSG0|;"_.undo" ;|MSG0|;"_end")
  158.   (setvar ;|MSG0|;"cmdecho" echo)             ; restore cmdecho sysvar
  159.   (princ)                             ; Quiet exit.
  160. )

BLANK隐藏实体 UNBLANKALL显示所有实体

点评

果然能这样就更好了: 1:加循环 2:选择对象后立即隐藏(不用右键确认) 3:可反向选择(隐藏未选择对象)  发表于 2012-4-1 10:06

评分

参与人数 1明经币 +1 收起 理由
669423907 + 1 yjr111大师总是那么热心!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2012-4-1 09:21:13 | 显示全部楼层
严哥这个在天正中多选择对象直接CAD崩溃,。卡住退出了哦。。不过也是很感谢

点评

问一下G版有没有办法破解段誉的六脉神剑哦:-)  发表于 2012-4-1 09:46
啥天正啊,AUTOCAD原版的程序也崩溃!  发表于 2012-4-1 09:45
回复

使用道具 举报

 楼主| 发表于 2012-4-1 09:51:02 | 显示全部楼层
当然G版肯出手一定行呵呵。。。
回复

使用道具 举报

 楼主| 发表于 2012-4-1 09:54:01 | 显示全部楼层
很关键滴是有些对象隐藏了显示不出来
回复

使用道具 举报

发表于 2012-4-1 10:02:24 | 显示全部楼层
flytoday 发表于 2012-4-1 09:21
严哥这个在天正中多选择对象直接CAD崩溃,。卡住退出了哦。。不过也是很感谢

额。。。天正的工具里不是有局部隐藏吗、、、
我也开着天正,用严哥这程序一切正常、、、、、8.5+2012
回复

使用道具 举报

发表于 2012-4-1 10:06:38 | 显示全部楼层
悲剧,确实对天正墙体之类的不能隐藏,一用就崩溃、、、、
回复

使用道具 举报

发表于 2012-4-1 10:07:21 | 显示全部楼层

点评

; 错误: Automation 错误...这个不能选择隐藏显示。。。  发表于 2012-4-1 10:35
回复

使用道具 举报

发表于 2012-4-1 10:19:17 | 显示全部楼层
Andyhon 发表于 2012-4-1 10:07
Ref:
http://www.mjtd.com/Codes/ArticleShow.asp?ArticleID=988

、、、、除了隐藏和显示所有,其他的都不会用、、、
暂时没有崩溃现象、、、
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-21 01:25 , Processed in 0.215070 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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