LAYFREEZE_LAYOFF_MULTIPLE_v2......................free

Command: LAYFREEZEMULTIPLE

This function freezes layers of selected multiple objects. Objects can be preselected. Function can work  in style of standard MATCHPROP command.

Command: LAYOFFMULTIPLE

As above but turns layers off

 

Code:

;;; ================================================
;;;        LAYFREEZE_LAYOFF_MULTIPLE_v2.LSP     
;;;
;;;        Written by Andrzej Kalinowski,     www.autolisps.blogspot.com
;;;        v1.00- 07.07.2018 - first release
;;;        v2- 23.04.2022 - LAYOFFMULTIPLE command added, corrected exiting objects selection loop
;;;
;;;        Command LAYFREEZEMULTIPLE
;;;            This function freezes layers of selected multiple objects. Objects can be preselected. Function can work  in style of standard MATCHPROP command.
;;;        Command LAYOFFMULTIPLE
;;;            As above but turns layers off
;;;        
;;; =======================================================
(vl-load-com)
(defun C:LAYFREEZEMULTIPLE (/ sset1 obj1 i1 CurObj Lay1 LayLst IsClay gr1) 	
    (setq sset1 nil)
    (setq gr1 1)
    (while (/= gr1 52)
        (setvar "ERRNO" 0);reset ERRNO to 0
        (setq sset1 (ssget "_:S" ) )
        (setq gr1 (getvar "ERRNO") )
        (if (= (getvar "ERRNO") 52) (exit))
        (if (= sset1 nil)
            (princ "\nWrong object");then
            (progn ;then
                (repeat (setq i1 (sslength sset1) );else
                    (setq
                        CurObj (ssname sset1 (setq i1 (1- i1) ) )
                        Lay1 (cdr (assoc 8 (entget CurObj) )  )
                    );setq
                    (if (= Lay1 (getvar "clayer"))
                        (setq IsClay 1) 
                        (if (= nil (member Lay1 LayLst) );EN: if already exist -it doesnt add it to the list
                            (setq LayLst (cons Lay1 LayLst) )
                        );if  
                    );end if
                );repeat
            );progn
        );if
        (setq i1 0)
        (repeat (length LayLst)
            (setq CurObj (nth i1 LayLst) )
            (princ CurObj) (terpri)
            (setq i1 (1+ i1))
            (vla-put-freeze      (vlax-ename->vla-object (tblobjname "LAYER" CurObj))         :vlax-true)
        );repeat
        (setq LayLst nil)
        (if (= IsClay 1)
            (princ "\nOne of selected layers is a current layer\n")
        );if
    );while
);defun

(defun C:LAYOFFMULTIPLE (/ sset1 obj1 i1 CurObj Lay1 LayLst IsClay kwrt1 gr1) 
    (setq doc1 (vla-get-activedocument (vlax-get-acad-object)))
    (vla-startundomark doc1)
    ;-----------------------------------------
    ; error section
    ;-----------------------------------------
    (defun *error* (msg) (princ "error: ") (princ msg) (princ) )
    (defun errtrap1 (errormsg1 /  )
        (setq *error* temperr)
        (setvar "DYNMODE" old_dynmode)
        (setvar "DYNPROMPT" old_dynprompt)
        (vla-endundomark doc1)
        (setq old_dynprompt nil old_dynmode nil doc1 nil temperr nil)
        (if (and errormsg1 (not (wcmatch (strcase errormsg1) "*BREAK*,*CANCEL*,*QUIT*") ) )
            (prompt (strcat "\n-------------------------\nError: " errormsg1) );then
        );if
        (princ)
    );defun err 
    ;-----------------------------------------
    ;setting system variables
    ;-----------------------------------------
    (setq 
        temperr *error* ;saving error
        *error* errtrap1 ; assigning errtrap1 function to *error* variable
        old_dynmode (getvar "DYNMODE")
        old_dynprompt (getvar "DYNPROMPT")
    );setq
    (setvar "DYNMODE" 3)
    (setvar "DYNPROMPT" 1)
    ;-----------------------------------------
    (setq obj1 1);setq
    (setq gr1 1)
    (while (/= gr1 52);infinite loop
        (setvar "ERRNO" 0);reset ERRNO to 0
        (setq sset1 (ssget "_:S" ) )
        (setq gr1 (getvar "ERRNO") )
        (if (= (getvar "ERRNO") 52) (exit))
        (if (= sset1 nil)
            (princ "\nWrong object");then
            (progn ;then
                (repeat (setq i1 (sslength sset1) );else
                    (setq
                        CurObj (ssname sset1 (setq i1 (1- i1) ) )
                        Lay1 (cdr (assoc 8 (entget CurObj) )  )
                    );setq
                    (if (= nil (member Lay1 LayLst) );if already exist -it doesnt add it to the list
                        (setq LayLst (cons Lay1 LayLst) )
                    );if  
                );repeat
            );progn
        );if
        (setq i1 0)
        (repeat (length LayLst)
            (setq CurObj (nth i1 LayLst) )
            (princ CurObj) (terpri)
            (setq i1 (1+ i1))
            (if (/= CurObj (getvar "clayer"))
                (vla-put-layeron    (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object) ) ) CurObj )         :vlax-false)
                (progn
                    (initget "Yes No")
                    (setq kwrt1 (getkword "\nDo you want to turn the current layer off? /N:"))
                    (if (or (= kwrt1 nil) (= kwrt1 "Yes") )
                        (vla-put-layeron    (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object) ) ) CurObj )         :vlax-false)
                    );if
                );progn
            );if
        );repeat
        (setq LayLst nil)
    );while
);defun

Example:

 

Version history:
v1.00- 07.07.2018 - first release
v2- 23.04.2022 - LAYOFFMULTIPLE command added, corrected exiting objects selection loop


File format:
.FAS


Compatibility:
-All Autocad
versions

Remarks:
-The application comes with the long command names listed above. To create your own short aliases for these commands, go to ACAD.PGP file or Menu Manage->Customization->Edit aliases->Edit Aliases.


Download file: LAYFREEZE_LAYOFF_MULTIPLE_v2.FAS

No comments:

Post a Comment