Jump to content

LISP for hiding/showing objects...


lamensterms

Recommended Posts

Great tool as well. Added to toolbar, but I need extension to VVA program, something works exactly like "Isolate Objects" in AutoCAD, but only extension to VVA program.

Let say I need to isolate two items from entire dwg, I select them and only this item stay visible and rest of them disappear.

Maybe header "Show selected only" is misleading. It s/b "Isolate selected only from entire dwg"

Sorry for confusion.

 

I'm confused. You want something that works exactly like "Isolate Objects". Why not just use the Isolate Objects command?

Link to comment
Share on other sites

Without reading the rest of the recent posts/code in detail... Methinks they're after a routine that modifies Visible Property (for entities not selected) instead of isolating by layer... Saw a similar discussion recently (think that one was at AUGI in a wish)

Link to comment
Share on other sites

Without reading the rest of the recent posts/code in detail... Methinks they're after a routine that modifies Visible Property (for entities not selected) instead of isolating by layer... Saw a similar discussion recently (think that one was at AUGI in a wish)

 

That's exactly what the IsolateObjects command does. It's been in c3d for a long time and has been in core for a while.

Link to comment
Share on other sites

Guest kruuger
Great tool as well. Added to toolbar, but I need extension to VVA program, something works exactly like "Isolate Objects" in AutoCAD, but only extension to VVA program.

Let say I need to isolate two items from entire dwg, I select them and only this item stay visible and rest of them disappear.

Maybe header "Show selected only" is misleading. It s/b "Isolate selected only from entire dwg"

Sorry for confusion.

ahh. now understand...

Link to comment
Share on other sites

That's exactly what the IsolateObjects command does. It's been in c3d for a long time and has been in core for a while.

 

I misread your post as 'layer isolate' in lieu of 'isolate objects'... My mistake.

 

Yes, IsolateObjects Command in deed does this (yay AECOBJECTISOLATEMODE system variable)... Too bad it does not include, nor honor the LAYISO settings (Off/Fade, etc.).

 

 

 

** ETA - For those who are unfamiliar with IsolateObjects Command, just be mindful of the ObjectIsolationMode system variable.

Link to comment
Share on other sites

this.Mode = Modes.Rant;

 

... Reflecting on this more, given the distinction between IsolateObjects, and HideObjects, I am surprised there is not already a "Ctrl" key toggle, as is the case with other Command combinations like Trim / Extend, etc. (think Visibility state changes in Block Editor).

Link to comment
Share on other sites

** ETA - For those who are unfamiliar with IsolateObjects Command, just be mindful of the ObjectIsolationMode system variable.

 

Agreed. Thankfully autocad is nice enough to have a yellow/red lightbulb button at the bottom right.

 

 

Since they are similar enough, I will post these quick hide and isolate commands. I use these randomly when I want one thing out of my way for a moment.

 

(defun c:HH (/ ss i)
 ;; temporarily hide pesky objects (regen will bring them back)
 ;; Alan J. Thompson
 (if (setq ss (ssget))
   (repeat (setq i (sslength ss)) (redraw (ssname ss (setq i (1- i))) 2))
 )
 (princ)
)


(defun c:II (/ tab all ss i e)
 ;; temporarily isolate selected objects (regen will bring them back)
 ;; Alan J. Thompson
 (setq tab (if (eq (getvar 'CVPORT) 1)
             '(410 . "Model")
             (cons 410 (getvar 'CTAB))
           )
       all (ssget "_A" (list tab))
 )
 (if (setq ss (ssget (list tab)))
   (repeat (setq i (sslength all))
     (redraw (setq e (ssname all (setq i (1- i))))
             (if (ssmemb e ss)
               1
               2
             )
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Very neat, Alan... Great usage of Redraw, IMO.

 

 

 

Here's one called EntFad (EntityFade), which honors one's own LayLockFadeCtrl system variable value:

 

 

Edit - Forgot to mention, that this supports Model, Layout, and PViewport Active.

 

Edit - Iterating a given Drawing's Model/Paper space Object can be dreadfully slow for large Drawings, especially so using LISP. I may port this to .NET and re-post for those who might benefit from the inherent speed of the latter API.

 

(defun c:ENTFAD () (c:EntityFade))
(defun c:EntityFade (/ fade ss acDoc ignoreList oLayer restoreLayerLockList)
 (if (and (< 0 (setq fade (getvar 'laylockfadectl)))
          (>= 90 fade)
          (setq ss (ssget))
     )
   (progn

     (defun bbox:EntityFadeCallback (rea cmd / oLayer restoreLayerLockList)
       (if (and (wcmatch (strcase (car cmd)) "*CLOSE,*REGEN,*SAVE*,*QUIT")
                *bbox_EntityFadeReactor*
           )
         (progn
           (vlr-remove *bbox_EntityFadeReactor*)
           (foreach item *bbox_RestoreFadeList*
             (if (= :vlax-true
                    (vla-get-lock
                      (setq oLayer
                             (vla-item (vla-get-layers
                                         (vla-get-activedocument
                                           (vlax-get-acad-object)
                                         )
                                       )
                                       (vla-get-layer x)
                             )
                      )
                    )
                 )
               (progn
                 (setq *bbox_RestoreLayerLockList*
                        (cons
                          oLayer
                          *bbox_RestoreLayerLockList*
                        )
                 )
                 (vla-put-lock oLayer :vlax-false)
               )
             )
             (vla-put-entitytransparency (car item) (cdr item))
           )
           (foreach layer restoreLayerLockList
             (vla-put-lock layer :vlax-true)
           )
           (foreach x '(*bbox_EntityFadeReactor*
                        bbox:EntityFadeCallback
                        *bbox_RestoreFadeList*
                       )
             (set x nil)
           )
         )
       )
     )

     (setq *bbox_EntityFadeReactor*
            (vlr-command-reactor
              "bbox hide entity reactor"
              '((:vlr-commandwillstart . bbox:EntityFadeCallback))
            )
     )

     (vlax-for x (setq ss
                        (vla-get-activeselectionset
                          (setq acDoc (vla-get-activedocument
                                        (vlax-get-acad-object)
                                      )
                          )
                        )
                 )
       (setq ignoreList (cons x ignoreList))
     )
     (vlax-for x (vlax-get acDoc
                           (if (= 1 (getvar 'tilemode))
                             'modelspace
                             (if (= 1 (getvar 'cvport))
                               'paperspace
                               'modelspace
                             )
                           )
                 )
       (if (not (vl-position x ignoreList))
         (progn
           (if (= :vlax-true
                  (vla-get-lock
                    (setq oLayer (vla-item (vla-get-layers acDoc)
                                           (vla-get-layer x)
                                 )
                    )
                  )
               )
             (progn
               (setq *bbox_RestoreLayerLockList*
                      (cons
                        oLayer
                        *bbox_RestoreLayerLockList*
                      )
               )
               (vla-put-lock oLayer :vlax-false)
             )
           )
           (setq *bbox_RestoreFadeList*
                  (cons
                    (cons x
                          (vla-get-entitytransparency x)
                    )
                    *bbox_RestoreFadeList*
                  )
           )
           (vla-put-entitytransparency x fade)
         )
       )
     )
     (foreach layer restoreLayerLockList
       (vla-put-lock layer :vlax-true)
     )
   )
   (if (not ss)
     (prompt "\n** LayLockFadeCtrl value must be 1-90 ** ")
   )
 )
 (princ)
)

 

** Note - I am unsure what version first implemented EntityTransparency Property, so some pre-2011 versions may not be able to use this.

Edited by BlackBox
Link to comment
Share on other sites

Looking back at the old(-er) code I posted, it could really use some updating... Never mind the obvious error handling, but it should also account for nested entities, and I should look into the newer features available to account for already locked (faded) layers, possibly un-fading the selected entities, etc..

 

In any event, hopefully it's of some use to the thread. *shrug*

Link to comment
Share on other sites

Looks like I am very late to the party. Sorry!!!

Was trying to mix VVA routine and AutoCAD "isolate objects" but, both (great) not working the same way.

It was only reason to ask for extension of VVA program. Hope he will join soon and help me.

Thank you all.

 

What I notice is when closing and opening dwg (with VVA program) it stay in stage as it was closed: object not visible stay invisible versus AutoCAD "Isolate objects" when all is visible after reopen dwg.

Edited by mdbdesign
ADD COMMENT
Link to comment
Share on other sites

What I notice is when closing and opening dwg (with VVA program) it stay in stage as it was closed: object not visible stay invisible versus AutoCAD "Isolate objects" when all is visible after reopen dwg.

 

That is why I included a reactor + callback in my offering, to restore the original status on Regen, Save*, Close, or Quit invocation... The same principle can be used in your situation (if IsolateObjects is somehow insufficient).

 

Cheers

Link to comment
Share on other sites

Only one question: Is possible to extend it to another option as "Show selected only"

Similar to AutoCAD's "Isolate Object".

I know it is older post but will waiting for answer.

Thank you again.

 

...

It was only reason to ask for extension of VVA program. Hope he will join soon and help me.

Edit #17 Try new version

Link to comment
Share on other sites

  • 8 months later...
Agreed. Thankfully autocad is nice enough to have a yellow/red lightbulb button at the bottom right.

 

 

Since they are similar enough, I will post these quick hide and isolate commands. I use these randomly when I want one thing out of my way for a moment.

 

(defun c:HH (/ ss i)
 ;; temporarily hide pesky objects (regen will bring them back)
 ;; Alan J. Thompson
 (if (setq ss (ssget))
   (repeat (setq i (sslength ss)) (redraw (ssname ss (setq i (1- i))) 2))
 )
 (princ)
)


(defun c:II (/ tab all ss i e)
 ;; temporarily isolate selected objects (regen will bring them back)
 ;; Alan J. Thompson
 (setq tab (if (eq (getvar 'CVPORT) 1)
             '(410 . "Model")
             (cons 410 (getvar 'CTAB))
           )
       all (ssget "_A" (list tab))
 )
 (if (setq ss (ssget (list tab)))
   (repeat (setq i (sslength all))
     (redraw (setq e (ssname all (setq i (1- i))))
             (if (ssmemb e ss)
               1
               2
             )
     )
   )
 )
 (princ)
)

 

Your code is very Good. But with Defun II not work in Viewport Layout. You can fix this problem... Thank you !

Edited by vnanhvu
Link to comment
Share on other sites

  • 7 years later...
On 6/2/2011 at 1:41 PM, VVA said:

a few more links

HideShow - hide selected objects from AutoCAD drawing (VLX for AutoCAD)

Easily hide and isolate objects in AutoCAD 2011

Freeze Object(s)

Quick and dirty

 


(defun c:invis (/ errCount wMode objSet showset actDoc *error*)
 ;; ==================================================================== ;;
 ;;                                                                      ;;
 ;;  INVIS.LSP - Makes objects temporarily invisible and                 ;;
 ;;              visible return of all or some                           ;;
 ;;                                                                      ;;
 ;; ==================================================================== ;;
 ;;                                                                      ;;
 ;;  Command(s) to call: INVIS                                           ;;
 ;;                                                                      ;;
 ;; ==================================================================== ;;
 ;;                                                                      ;;
 ;;  THIS PROGRAM AND PARTS OF IT MAY REPRODUCED BY ANY METHOD ON ANY    ;;
 ;;  MEDIUM FOR ANY REASON. YOU CAN USE OR MODIFY THIS PROGRAM OR        ;;
 ;;  PARTS OF IT ABSOLUTELY FREE.                                        ;;
 ;;                                                                      ;;
 ;;  THIS PROGRAM PROVIDES 'AS IS' WITH ALL FAULTS AND SPECIFICALLY      ;;
 ;;  DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS        ;;
 ;;  FOR A PARTICULAR USE.                                               ;;
 ;;                                                                      ;;
 ;; ==================================================================== ;;
 ;;                                                                      ;;
 ;;  V1.1, 11th Apr 2005, Riga, Latvia                                   ;;
 ;;  © Aleksandr Smirnov (ASMI)                                          ;;
 ;;  For AutoCAD 2000 - 2008 (isn't tested in a next versions)           ;;
 ;;                                                                      ;;
 ;;http://www.cadtutor.net/forum/showthread.php?43876-AsmiTools          ;;
 ;; ==================================================================== ;;
 ;;                                                                      ;;
 ;;  V1.2, 02 June 2011, Minsk, Belarus                                  ;;
 ;;  © Vladimir Azarko (VVA)                                             ;;
 ;;  For AutoCAD 2000 - 2011 (isn't tested in a next versions)           ;;
 ;; Add mode "Show some object"                                          ;;
 ;;  V1.3, 04 may 2013, Minsk, Belarus                                   ;;
 ;;  © Vladimir Azarko (VVA)                                             ;;
 ;;  For AutoCAD 2000 - 2011 (isn't tested in a next versions)           ;;
 ;; Add mode "Show selected Only"                                        ;;
 ;;                                                                      ;;
 ;;http://www.cadtutor.net/forum/showthread.php?59655                    ;;
 ;; ==================================================================== ;;
 ;;                                                                      ;;

 (vl-load-com)
 (defun put_Visible_Prop (Object Flag)
   (if
     (vl-catch-all-error-p
(vl-catch-all-apply
  'vla-put-visible
  (list Object Flag)
)
     )
      (setq errCount (1+ errCount))
   );_ end if
   (princ)
 );_ end of put_Visible_Prop
 (defun Set_to_List (SelSet)
   (mapcar 'vlax-ename->vla-object
    (vl-remove-if
      'listp
      (mapcar 'cadr (ssnamex SelSet))
    )
   )
 );_ end of Set_to_List
 (defun errMsg	()
   (if	(/= 0 errCount)
     (princ (strcat ", "
	     (itoa errCount)
	     " were on locked layer."
     )
     )
     "."
   );_ end if
 );_ end of errMsg
 (setq	actDoc	 (vla-get-ActiveDocument
	   (vlax-get-Acad-object)
	 )
errCount 0
 );_ end setq
 (vla-StartUndoMark actDoc)
 (initget "Visible Invisible Show Only" 1)
 (setq	wMode
 (getkword
   "\nMake objects [Visible all/Invisible/Show some invisible objects/show selected Only]: "
 )
 )
 (cond
   ((and
      (= wMode "Visible")
      (setq objSet (ssget "_X" '((60 . 1))))
    );_ end and
    (setq objSet (Set_to_List objSet))
    (mapcar
      '(lambda (x) (put_Visible_Prop x :vlax-true))
      objSet
    )
    (princ
      (strcat "\n<< "
       (itoa (- (length objSet) errCount))
       " now visible"
       (errMsg)
       " >>"
      )
    )
   ) ;_ # condition
   ((and
      (= wMode "Show")
      (setq objSet (ssget "_X" '((60 . 1))))
    );_ end and
    (setq objSet (Set_to_List objSet))
    (mapcar
      '(lambda (x) (put_Visible_Prop x :vlax-true))
      objSet
    )
    (princ
      (strcat "\n<< "
       (itoa (- (length objSet) errCount))
       " now visible"
       (errMsg)
       " >>"
      )
    )
    (princ "\nSelect objects to show")
    (if (setq showset (ssget "_:L"))
      (progn
 (setq showset (Set_to_List showset))
 (foreach item showset
   (setq objSet (vl-remove item objSet))
 )
 (mapcar
   '(lambda (x) (put_Visible_Prop x :vlax-false))
   objSet
 )
      )
    )
   ) ;_ # condition
   ((= wMode "Only")
    (if (not (setq objSet (ssget "_I")))
      (setq objSet (ssget))
    ) ;_ end if
    (if (and objset (setq objSet (Set_to_List objSet)))
      (progn
 (setq showset (ssget "_X" (list (cons 410 (getvar 'Ctab))))
       showset (Set_to_List showset)
 )
 (foreach item objSet
   (setq showset (vl-remove item showset))
 )
 (mapcar
   '(lambda (x) (put_Visible_Prop x :vlax-false))
   showset
 )
 (princ
   (strcat "\n<< "
	   (itoa (- (length showset) errCount))
	   " now invisible"
	   (errMsg)
	   " >>"
   )
 )
      )
    )
   ) ;_ # condition
   (t
    (if (not (setq objSet (ssget "_I")))
      (setq objSet (ssget))
    );_ end if
    (if objSet
      (progn
 (setq objSet (Set_to_List objSet))
 (mapcar
   '(lambda (x) (put_Visible_Prop x :vlax-false))
   objSet
 )
 (princ
   (strcat "\n<< "
	   (itoa (- (length objSet) errCount))
	   " now invisible"
	   (errMsg)
	   " >>"
   )
 )
      );_ end progn
    );_ end if
   )
 );_ end cond
 (vla-EndUndoMark actDoc)
 (princ)
);_ end of c:invis
(mapcar 'princ
(list
 "\n[info] http://www.cadtutor.net/forum/showthread.php?59655 [info]"
 "\nType INVIS to make objects invisible or visible."
)
)	
(princ)
 

 

 

I've been using this lisp on a 2011 version. I've tried it a 2022 version, and it's not working. Can someone figure out how it will work on a latest Autocad version. Looking forward for your responses. Thank you in advance.

Link to comment
Share on other sites

Can you give more info? Does it give an error?

 

-edit-

This is a new install I take it? Double check you have the full lisp installed/loaded.

Edited by mhupp
Link to comment
Share on other sites

It isn't something I have used but a quick check on my AutoCAD 2021 and it works OK, so like Mhupp says, will need a bit more info about why it isn't working. Is it the whole thing not working or just 1 part, is there an error message and what does it say, where does it stop working.... but "this is broken" doesn't really help a lot

  • Agree 1
Link to comment
Share on other sites

  • 3 months later...
On 5/2/2013 at 2:11 AM, alanjt said:

 

Agreed. Thankfully autocad is nice enough to have a yellow/red lightbulb button at the bottom right.

 

 

Since they are similar enough, I will post these quick hide and isolate commands. I use these randomly when I want one thing out of my way for a moment.

 

 

(defun c:HH (/ ss i)
 ;; temporarily hide pesky objects (regen will bring them back)
 ;; Alan J. Thompson
 (if (setq ss (ssget))
   (repeat (setq i (sslength ss)) (redraw (ssname ss (setq i (1- i))) 2))
 )
 (princ)
)


(defun c:II (/ tab all ss i e)
 ;; temporarily isolate selected objects (regen will bring them back)
 ;; Alan J. Thompson
 (setq tab (if (eq (getvar 'CVPORT) 1)
             '(410 . "Model")
             (cons 410 (getvar 'CTAB))
           )
       all (ssget "_A" (list tab))
 )
 (if (setq ss (ssget (list tab)))
   (repeat (setq i (sslength all))
     (redraw (setq e (ssname all (setq i (1- i))))
             (if (ssmemb e ss)
               1
               2
             )
     )
   )
 )
 (princ)
)
 

 

 

 

Hello Everyone,

I'm looking for the same script to work on my Huge size drawing file., but instead of  select all i would like to isolate only Line and Polylines from Selected objects. Can someone help me on this.

Link to comment
Share on other sites

In there there is a comment "ssget", line 1 of the code, which can be modified to select what you want. This is a good reference http://lee-mac.com/ssget.html . 

 

So might be you change that line to 

 

(if (setq ss (ssget '((0 . "*LINE"))))

 

the * before 'LINE' being a wildcard to also include polylines.

 

So see if you can work out routine 'II' modifications....

Ask if this doesn't make sense of course

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...