Print Page | Close Window

Show/hide object in current viewport

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DWF formats, Design Review, AutoCAD 360, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=5805
Printed Date: 31.May.2026 at 23:19


Topic: Show/hide object in current viewport
Posted By: suribalu
Subject: Show/hide object in current viewport
Date Posted: 03.May.2011 at 06:38

It would be a great help if there is a way to show or hide a object only in the current viewport without affecting its visibility in model space or other viewports.

I came across a .vlx file from http://www.cadstudio.cz/dl./hideshow.vlx" rel="nofollow - www.cadstudio.cz/dl./hideshow.vlx that does the job of showing or hiding in model space( and hence in all viewports).
 
If someone got a lisp routine for object display just affecting the current viewport, it'll be real help.
 
Thanks,
Suribalu



Replies:
Posted By: John Connor
Date Posted: 03.May.2011 at 12:14
Put the object on its own layer and use the viewport freeze option available in the Layer Properties Manager.

-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: alanjt
Date Posted: 03.May.2011 at 14:50
You can also accomplish this with commands: LayFrz and VPLayer.


Posted By: suribalu
Date Posted: 04.May.2011 at 01:19
Thanks for the replies. By doing VP freeze or LAYFRZ I would be applying to the entire layer(which turns off all the objects in that layer). I just want a specified object in a layer to be turned off in a specified viewport(not affecting its visibility in model space or any other viewport).
Please find below couple of LISP files I came across few websites that posted LISP files which can turn on/off a object (not layer) in model space. If some pros at autolisp could look at it and modify it to the way I need it will save my day(s).  Thanks in advance,
Suribalu
;Tip1504: ELEMS.LSP Freeze Elements (c)1999, Pawel Lewicki
(defun c:ELEMS (/ odp count ss s1 dxf old-name xd appl)
(setvar "cmdecho" 0)
(setq appl "ELEMS")
(if (not (tblsearch "appid" appl)) (regapp appl) )
(initget "? ON OFF Freeze Thaw Lock Unlock")
(setq odp (getkword "\n?, ON, OFF, Freeze, Thaw, Lock, Unlock : "))
(cond ( (= odp "ON") (RESTORE-LAYR "ELEMS-OFF") )
( (= odp "Thaw") (RESTORE-LAYR "ELEMS-Freeze") )
( (= odp "Unlock") (RESTORE-LAYR "ELEMS-Lock") )
( (= odp "OFF") (CHANGE-LAYR "ELEMS-OFF") )
( (= odp "Freeze") (CHANGE-LAYR "ELEMS-Freeze") )
( (= odp "Lock") (CHANGE-LAYR "ELEMS-Lock") )
( (= odp "?") (ELEMS-INFO) )
)
(princ)
);defun
(defun ELEMS-INFO ()
(foreach layr-name '("ELEMS-OFF" "ELEMS-Freeze" "ELEMS-Lock")
(setq ss (ssget "_X" (list (cons 8 layr-name)) ))
(if ss (princ (sslength ss)) (princ "0") )
(princ (strcat " elements on layer " layr-name "\n") )
)
)
(defun CHANGE-LAYR (layr-name)
(setq ss (ssget))
(if ss (progn
(command "_layer" "_n" layr-name (strcat "_" odp) layr-name "")
(setq count 0)
(while (setq s1 (ssname ss count))
(setq dxf (entget s1))
(setq old-name (cdr (assoc 8 dxf)))
(setq xd (list (LIST -3 (LIST appl
(cons 1002 "{")
(cons 1003 old-name)
(cons 1002 "}")
))))
(setq dxf (subst (cons 8 layr-name) (assoc 8 dxf) dxf))
(setq dxf (append dxf xd))
(entmod dxf)
(setq count (+ 1 count))
)
));if
);defun
(defun RESTORE-LAYR (layr-name)
(setq ss (ssget "_x" (list (cons 8 layr-name)) ))
(if ss (progn
(setq count 0)
(if (= layr-name "ELEMS-Lock") (command "_layer" "_Unlock" layr-name "") )
(while (setq s1 (ssname ss count))
(setq dxf (entget s1 (list appl)))
(setq xd (car (cdr (assoc -3 dxf))))
(setq old-name (cdr (nth 2 xd)))
(setq dxf (subst (cons 8 old-name) (assoc 8 dxf) dxf))
(setq dxf (reverse (cdr (reverse dxf))))
(entmod dxf)
(setq count (+ 1 count))
)
(if (= layr-name "ELEMS-Lock") (command "_layer" "_Lock" layr-name "") )
))
(princ count) (princ " elements") (princ)
);defun
http://www.cadtutor.net/forum/archive/index.php/t-31330.html" rel="nofollow - http://www.cadtutor.net/forum/archive/index.php/t-31330.html
 
;; Turn off visibility for selected objects
(defun c:OFF (/ ss)
  (vl-load-com)
  (prompt "\n Select objects to hide: ")
  (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))
 
;; Turn on visibility for all objects
(defun c:ON (/ ss)
  (vl-load-com)
  (prompt "\n Turning on visibility for all objects... ")
  (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))
http://www.augi.com/forums/showthread.php?t=125514" rel="nofollow - http://www.augi.com/forums/showthread.php?t=125514


Posted By: John Connor
Date Posted: 04.May.2011 at 11:54
There is a lisp routine I've seen that will make individual objects "invisible".  Would that be what you are looking for?

-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: suribalu
Date Posted: 04.May.2011 at 12:46
Thanks mate for the reply. If the lisp routine you mentioned can make objects invisible just from a specific viewport while leaving the visibility in model space then that's what I'd be looking for.
Regards,
Suribalu


Posted By: John Connor
Date Posted: 04.May.2011 at 18:18
Nope.  You would be better off putting the object on its own layer and using viewport freeze.

-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>




Print Page | Close Window