;------------------------------------------------------------------------------ ; CAD Concepts ; ; Object Visibility (HideTheHelp) ; ; Copyright (C) 2016 CAD Concepts Limited. ; ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program. If not, see . ;------------------------------------------------------------------------------ ; ; File : CCL-HideTheHelp.lsp ; Author : Jason Bourhill ; Web : http://www.cadconcepts.co.nz ; Date : 05/05/2016 ; CAD Ver(s) : Bricscad V16 ; ; PURPOSE: ; Add, remove, and change the visibility of helper objects used in ; BricsCAD parametric models. These helper objects are kept together ; in the HIDETHEHELP group. ; ; USAGE: ; To load type (load "CCL-HideTheHelp.lsp") from the command line ; or drag and drop the file onto your drawing using explorer. ; ; COMMANDS: ; ; HIDETHEHELP ; This command has the following options: ; CCL-HideTheHelp: Visible/Invisible/Add/Remove/ ; ; VISIBLE ; Shows all the objects in the drawing belonging to the HIDETHEHELP group. ; ; INVISIBLE ; Hides all the objects in the drawing belonging to the HIDETHEHELP group. ; ; ADD ; Allows you to select blocks to add to the HIDETHEHELP group. ; ; REMOVE ; Allows you to select blocks to remove from the HIDETHEHELP group. ; ; EXIT ; exits the application ; ; Once you've created a group, then you can use the TTH command to quickly ; toggle visibility on/off. ; ; TTH ; This command will allow you to quickly toggle the visibility of objects ; in the HIDETHEHELP group ; ; RESETVIS ; This command resets the visibility of ALL objects on the drawing to ; be visible. This is useful for the situation where invisible objects ; are on the drawing, but don't belong to any group. ; ; NOTES: ; This application uses a GROUP called HIDETHEHELP to hold the objects ; you want to be able to control the Visibility of. This group will be ; created automatically if it doesn't already exist. ; ; If you use the 'Open Copy' option fron the Mechanical Browser it won't ; copy the HIDETHEHELP group. You can reset the visibility of any ; hidden entities by loading this application, then copy and pasting the ; following code in at the command line ; (foreach ent (vle-selectionset->list (ssget "X")) (CCL-VISIBILITY ent 1)) ; This doesn't recreate the group, you will need to run HideTheHelp and ; use the 'Add' option to do this. ; ; REQUIRES: (load "vle-extension.lsp" "VLE Library Extensions") ; VLE Library Emulation ; VLE extensions source http://www.bricsys.com/applications/a/?lisp-developer-support-package-%28ldsp%29-a720-al1176 (vl-load-com) ; Load the visual lisp extensions. Required for AutoCAD ; ------------------------------------------------------------------------------- ; Rev no : A ; Rev Date : 05/05/2016 ; Rev by : Jason Bourhill ; Web : http://www.cadconcepts.co.nz ; ; Description: ; First Issue ; ------------------------------------------------------------------------------- ; Rev no : B ; Rev Date : 20/06/2016 ; Rev by : Jason Bourhill ; Web : http://www.cadconcepts.co.nz ; ; Description: ; Added TTH command to quickly toggle visibility ; ------------------------------------------------------------------------------- ; Rev no : C ; Rev Date : 28/10/2016 ; Rev by : Jason Bourhill ; Web : http://www.cadconcepts.co.nz ; ; Description: ; Added RESETVIS command to allow resetting the visibility of ALL objects ; irrespective of whether they are in the HIDETHEHELP group or not. ; ------------------------------------------------------------------------------- ; CCL-VISIBILITY ; Change the visibility of the given entity ; requires entityname and visibility ; 3 possibly visibility actions ; 0 = Invisible ; 1 = Visibile ; -1 = Toggle current state ; (CCL-VISIBILITY (car (entsel)) 0) (defun CCL-VISIBILITY (ent vis / obj objstate) (vl-load-com); Make sure the visual lisp extensions are available. Required by AutoCAD. (setq obj (vlax-ename->vla-object ent)) ; retrieve the object (cond ((= vis 0) (setq objstate ':VLAX-FALSE)) ; Off ((= vis 1) (setq objstate ':VLAX-TRUE)) ; On ((= vis -1) (setq objstate (if (= (vla-get-visible obj) ':VLAX-TRUE) ':VLAX-FALSE ':VLAX-TRUE))) ; Toggle ) (if objstate (vla-put-visible obj objstate)) ; If objstate has been set, then update VISIBILITY ); end DEFUN CCL-VISIBILITY ;CCL-GROUP->SSET ;Returns a selection set containing all the objects belonging to the given group ;(CCL-GROUP->SSET "MYGROUP") (defun CCL-GROUP->SSET (groupname / sset grpdict grouplist) (setq sset (ssadd)) ; initialise selection set (setq grpdict (dictsearch (namedobjdict) "ACAD_GROUP")) ; retrieve group dictionary (setq grouplist (dictsearch (cdar grpdict) groupname)) ; retrieve details on given group (while grouplist ; work our way through the grouplist (setq grouplist (member (assoc 340 grouplist) grouplist)) ; find objects in the group (if grouplist (progn (setq sset (ssadd (cdar grouplist) sset)) ; add object to selection set (setq grouplist (cdr grouplist)) ; iterate to next objects in the group ) ) ) (if (> (sslength sset) 0) sset) ; return the selection set if its been populated ) ; CCL-GROUP-OBJ ; Returns the vla object of the given group. ; Will create the group if it doesn't alread exist ; created group will be set as non-selectable, which is desirable in this case (defun CCL-GROUP-OBJ (groupname / oADOC oGROUPS selectable oGRP) (setq oADOC (vla-get-activedocument (vlax-get-acad-object))) ;retrieve a reference to the documents object (setq oGROUPS (vla-get-groups oADOC )) ;retrieve a reference to the groups object (setq selectable 0) ; Set the selectabilty of the group 1 = selectable 0 = non-selectable (if (vl-catch-all-error-p (setq oGRP (vl-catch-all-apply 'vla-item (list oGROUPS groupname)) ) ) (progn (setq oGRP (vla-add oGROUPS groupname)) ; Then create it ;;active X interface does not include a property for group selectability ;;so convert the vla-object -> ename and vle-entmod (vle-entmod 71 (vlax-vla-object->ename oGRP) selectable) ; set the groups selectability ) ) oGRP ) ; CCL-MODGROUP ; Adds or removes entities from the given GROUP name ; requires group name, selection set of objects to add/remove, and flag to determine action. ; If the group name doesn't already exist, then it will be created. ; (CCL-MODGROUP "MYGROUP" MySSet T) ; will ADD objects in MySSet to the group named MYGROUP ; (CCL-MODGROUP "MYGROUP" MySSet nil) ; will REMOVE objects in MySSet from the group named MYGROUP (defun CCL-MODGROUP (groupname sset opt / oADOC oGROUPS oGRP action numobjs obj oList moderror) (setq oADOC (vla-get-activedocument (vlax-get-acad-object))) ;retrieve a reference to the documents object (setq oGROUPS (vla-get-groups oADOC )) ;retrieve a reference to the groups object (setq oGRP (CCL-GROUP-OBJ groupname)) ; retrieve object for our group, creating it if it doesn't already exist ; (if (not oGRP) ; if it doesn't exist ; (setq oGRP (vla-add oGROUPS groupname)) ; Then create it ; ) (setq currobjs (vle-collection->list oGRP)) ; retrieve a list of the objects that are currently in this group (setq numobjs (vla-get-count oGRP)) ; find number objects currently in the group (cond ((= opt nil) ; REMOVE objects from group (setq action 'vla-removeitems) ; set action to take (foreach ent (vle-selectionset->list sset) ; for each object in the selection set (if (member (setq obj (vlax-ename->vla-object ent)) currobjs) ; Check that the object is a group member (setq oList (cons obj oList)) ; add to list of objects to REMOVE ) ) ) ((= opt T) ; ADD objects to group (setq action 'vla-appenditems) ; set action to take (foreach ent (vle-selectionset->list sset) ; for each object in the selection set (if (not (member (setq obj (vlax-ename->vla-object ent)) currobjs)) ; Check that the object is NOT a group member (setq oList (cons obj oList)) ; add to list of objects to ADD ) ) ) ) (if oList ; if a list of objects to add/remove has been created (progn ; Then convert the list to a safearray, then to a variant (setq oList (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbObject (cons 0 (1- (length oList)))) oList ) ) ) (setq moderror (vl-catch-all-apply action (list oGRP oList))) ; add/remove objects from group ; (if moderror ; (princ (Strcat "\n" (vl-catch-all-error-message moderror))) ; If there is an error, display it. ; (princ "\nNo Error") ; ) ) ) (setq numobjs (abs (- (vla-get-count oGRP) numobjs))) ; determine change in the number of objects belonging to the group (mapcar 'vlax-release-object (list oADOC oGROUPS oGRP)) ; release-objects numobjs ) ; CCL-GROUPSETVIS ; Sets the visibility of objects in the given GROUP. ; returns the no of objects that have had their Visibility state changed. ; 3 possibly visibility actions ; 0 = Invisible ; 1 = Visibile ; -1 = Toggle current state ; (CCL-GROUPSETVIS "MYGROUPNAME" 1) (defun CCL-GROUPSETVIS ( groupname vis / num sset) (setq num 0) ; initialise counter (setq sset (CCL-GROUP->SSET groupname)) ; create a selections set with all entities belonging to the given group (if sset ; if selection set created (foreach ent (vle-selectionset->list sset) (CCL-VISIBILITY ent vis) ; set visibility (setq num (1+ num)) ; Iterate counter ) ) num ) ; RESETVIS ; Resets the visibility of all objects on the drawing. ; returns the num of objects that have had their Visibility state changed. (defun C:RESETVIS ( / num sset) (setq num 0) ; initialise counter (setq sset (ssget "X")) ; create a selections set with all entities belonging to the given group (if sset ; if selection set created (foreach ent (vle-selectionset->list sset) (CCL-VISIBILITY ent 1) ; set visibility (setq num (1+ num)) ; Iterate counter ) ) num ) (defun C:HIDETHEHELP ( / CCL-GROUPADD CCL-GROUPREM groupname flag ans num) ; CCL-GROUPADD ; Allows the user to ADD objects to the given group name ; and sets visibility (defun CCL-GROUPADD ( groupname vis / groupname sset num) (princ (strcat "\nSelect Entities to ADD to the " groupname " group")) (setq sset (ssget)) (if sset (progn (setq num (CCL-MODGROUP groupname sset T)) (princ (strcat "\n" (itoa num) " Blocks ADDED to " groupname " group.")) (CCL-GROUPSETVIS groupname vis) ; change objects visiblity too ) (princ "\nNo entities selected") ) (prin1) ) ; CCL-GROUPEM ; Allows the user to REMOVE objects from the given group name ; and sets visibility (defun CCL-GROUPREM ( groupname vis / *ERROR* groupname currobj sset num) ; Error handler in case the user cancels ; Makes sure that the group highlighting and visibility is reset (defun *ERROR* ( msg ) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\nError: " msg)) ) (foreach ent (vle-selectionset->list currobj) (redraw ent 4)) ; unhighlight the objects (CCL-GROUPSETVIS groupname vis) ; reset the objects visiblity (princ) ) (CCL-GROUPSETVIS groupname 1) ; make the group visible (setq currobj (CCL-GROUP->SSET groupname)) ; find the current objects (if currobj (progn (foreach ent (vle-selectionset->list currobj) (redraw ent 3)) ; highlight the objects currently in the group (princ (strcat "\nSelect Entities to REMOVE from the " groupname " group")) (setq sset (ssget)) (foreach ent (vle-selectionset->list currobj) (redraw ent 4)) ; unhighlight the objects (if sset (progn (setq num (CCL-MODGROUP groupname sset nil)) (princ (strcat "\n" (itoa num) " Entities REMOVED from " groupname " group.")) ) (princ "\nNo entities selected") ) ) (princ "\nNo entities found to remove") ) (CCL-GROUPSETVIS groupname vis) ; reset the objects visiblity (prin1) ) ; MAIN Program ;------------------------------------------------------------------------------ (setq groupname "HIDETHEHELP") ; set the GROUP name to work with (setq flag T) ; initialise flag (while flag (initget "Visible Invisible Add Remove eXit") (setq ans (getkword "\nCCL-HIDETHEHELP: Visible/Invisible/Add/Remove/: ")) (cond ((= ans "Visible") (setq *CCL-entvis* 1) (setq num (CCL-GROUPSETVIS groupname 1)) ; make visibile (princ (strcat "\n" (itoa num) " Entities made Visible.")) ) ((= ans "Invisible") (setq *CCL-entvis* 0) (setq num (CCL-GROUPSETVIS groupname 0)) ; make Invisibile (princ (strcat "\n" (itoa num) " Entities made Invisible.")) ) ((= ans "Add") (setq *CCL-entvis* (if *CCL-entvis* *CCL-entvis* 0)) (CCL-GroupAdd groupname *CCL-entvis*) ) ((= ans "Remove") (setq *CCL-entvis* (if *CCL-entvis* *CCL-entvis* 0)) (CCL-GroupRem groupname *CCL-entvis*) ) (T (setq flag nil)) ) ) (prin1) ) ; Toggle visibility ; Toggle The Help (defun C:TTH ( / groupname num) (setq groupname "HIDETHEHELP") ; set the GROUP name to work with (setq num (CCL-GROUPSETVIS groupname -1)) (princ (strcat "\nToggled visibility on " (itoa num) " Entities.")) (prin1) ) (princ "\nHide the Help Loaded. Commands: HIDETHEHELP, TTH, RESETVIS.") (prin1)