明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3116|回复: 7

老师,我想请教-下怎样用Visual lisp编程隐藏实体和显示实体??

[复制链接]
发表于 2002-8-1 17:21:00 | 显示全部楼层 |阅读模式
发表于 2002-8-2 08:27:00 | 显示全部楼层

用lisp编程隐藏实体和显示实体如內,但用visual lisp编程的就沒有了!!!

;;;---------------------------------------------------------------------------;
;;;
;;;   BLANK.LSP   Version 1.0
;;;
;;;   Copyright (C) 1995 by Autodesk, Inc.
;;;
;;;   Permission to use, copy, modify, and distribute this software and its
;;;   documentation for any purpose and without fee is hereby granted.
;;;
;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
;;;   ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
;;;   MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;
;;;---------------------------------------------------------------------------;
;;;   BLANK, UNBLANK, and UNBLANKALL
;;;
;;;   This module provides functions to manipulate the visibility field of
;;;   AutoCAD objects.  BLANK will make a selection set of objects invisible.
;;;   UNBLANK will make a specified object (given its handle) visible.
;;;   UNBLANKALL will make all blanked entities visible.
;;;
;;;---------------------------------------------------------------------------;


;;;---------------------------------------------------------------------------;
;;; Internal error handling.
;;;---------------------------------------------------------------------------;
(defun blank_error(s)
  ;; The strings in the following statements can be translated.
  (if (/= s ;|MSG1|;"Function cancelled")
    (princ (strcat ;|MSG2|;"\nBLANK Error: " s))
  )
  (setq *error* olderr)
  (princ)
)

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

(defun blank60 (e / e2)
  (if (not (null (assoc '60 e)))
    (setq e2 (subst '(60 . 1) '(60 . 0) e))
    (setq e2 (append e '((60 . 1))))
  )
)   

(defun show60 (e / e2)
  (if (not (null (assoc '60 e)))
     (setq e2 (subst '(60 . 0) '(60 . 1) e))
     (setq e2 (append e '((60 . 0))))
  )
)

(defun setvis ( vis ename / e)
  (setq e (entget ename))
  (if (eq vis 0)
     (entmod (show60 e))
     (entmod (blank60 e))
  )
  (entupd ename)
  ;; Blank vertices of polyline, if necessary
  (if (eq (cdr (nth 1 e)) "OLYLINE")
    (progn
      (setq ename (entnext ename))
      (setq e (entget ename))
      (while (eq (cdr (nth 1 e)) "VERTEX")
        (if (eq vis 0)
           (entmod (show60 e))
           (entmod (blank60 e))
        )
        (entupd ename)
        (setq ename (entnext ename))
        (setq e (entget ename))
      ) ; while
    ) ; progn
  ) ; if polyline
  (if (and (eq (cdr (nth 1 e)) "INSERT")
           (assoc '66 e))
    (progn
      (setq ename (entnext ename))
      (setq e (entget ename))
      (while (eq (cdr (nth 1 e)) "ATTRIB")
        (if (eq vis 0)
           (entmod (show60 e))
           (entmod (blank60 e))
        )
        (entupd ename)
        (setq ename (entnext ename))
        (setq e (entget ename))
      ) ; while
    ) ; progn
  )
)

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

  (setq ss (ssget))
  (setq i 0)
  (while (< i (sslength ss)) (progn
     (setq ename (ssname ss i))
     (setvis 1 ename)
     (setq i (1+ i))
  ))

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

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

  ;; Select all blanked entities
  (setq ss (ssget ;|MSG0|;"_x" '((60 . 1))))
  (if (not (null ss))
    (progn
      (setq i 0)
      (princ (sslength ss))
      (princ " blanked entities found.\n");
      ;; Unblank each entity in the set
      (while (< i (sslength ss)) (progn
         (setq ename (ssname ss i))
         (setvis 0 ename)
         (setq i (1+ i))
      ))
    )   
    (princ "\n0 blanked entities found.\n");
  )

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

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

  (setq hand (getstring ;|MSG5|;"\nEnter handle of entity to be unblanked: "))
  ;; Unblank the entity if handle is not an empty string
  (if (> (strlen hand) 0)
    (progn
      (setq ename (handent hand))
      (if (/= nil ename)
        (setvis 0 ename)
        (princ ;|MSG6|;"Invalid handle.")
      )
    )
  )

  (setq *error* old_error)            ; restore error function
  (command ;|MSG0|;"_.undo" ;|MSG0|;"_end")
  (setvar ;|MSG0|;"cmdecho" echo)             ; restore cmdecho sysvar
  (princ)                             ; Quiet exit.
)
(princ)
 楼主| 发表于 2002-8-2 19:55:00 | 显示全部楼层

谢谢老师,不愧为高手!

 楼主| 发表于 2002-8-3 10:05:00 | 显示全部楼层

你的程序我看了一下,请问(setvar ;|MSG0|;"cmdecho" 0)怎样理解?

 楼主| 发表于 2002-8-3 10:29:00 | 显示全部楼层

程序中unblank函数不知怎样用??

发表于 2002-8-18 14:57:00 | 显示全部楼层

我简化了一下这个程序

(defun blank60 (e / e2)
  (if (not (null (assoc '60 e)))
    (setq e2 (subst '(60 . 1) '(60 . 0) e))
    (setq e2 (append e '((60 . 1))))
  )
)   

(defun show60 (e / e2)
  (if (not (null (assoc '60 e)))
     (setq e2 (subst '(60 . 0) '(60 . 1) e))
     (setq e2 (append e '((60 . 0))))
  )
)
(defun getType(e / type)
  (setq type 0)
  (if (assoc 60 e)
    (setq type (cdr (assoc 60 e)))
  )   
  type
)
(defun c:swd(/ ss n en el)
  (setq ss (ssget))
  (if ss
    (setq n (sslength ss))
    (setq n 0)
  )
  (repeat n
    (setq en (ssname ss (setq n (1- n)))
          el (entget en)
     )     
     (if (= (getType el) 0)
        (setq el (blank60 el))
        (setq el (show60 el))        
     )
    (entmod el)
  )
  (princ)
)
;其实Lisp程序可用于ALISP中
发表于 2009-1-22 10:24:00 | 显示全部楼层

搜了半天了,虽是老帖,但是好贴,还是要顶一下!

发表于 2011-12-3 15:58:16 | 显示全部楼层
嗯,的确好贴,顶起!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-4-30 17:48 , Processed in 0.194723 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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