Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

LAYER-ISOLATE FROM OFF TO FREEZE

Status
Not open for further replies.

pardal

Automotive
Oct 17, 2001
444
At BONUS tools there is one that Isolate one layer from the all others, doing (OFF) the remaining layers, by this way if I need to do a ZOOM to Ext, it do to the limit of the bigest layer "turned off".
What I intend to do ,is if possible, is to do the LAYISO to FREEZE the remaining layers.

The lisp file that do this task is
BNSLAYER.lsp. as follow at the end of this message.It can bbe found at the BONUS/Cadtools directory too.

I tried to change the "OFF" to "F" at this line
(command "_.-LAYER" "_OFF" "*" "_Y")

in this way

(command "_.-LAYER" "_F" "*" "_Y")

but when I ran it I get the message error that can not freeze the current layer.

Does any one know how to modify it so the isolating is doing by mean of freezen the not selected layer so when I do a Zoom Extend , I get the whole draw filling the screen??


********************


;;; BNSLAYER.LSP
;;; Copyright (C) 1997 by Autodesk, Inc.
;;;
;;; Created 2/21/97 by Dominic Panholzer
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
;;; AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
;;; MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
;;; DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
;;; UNINTERRUPTED OR ERROR FREE.
;;;
;;; Use, duplication, or disclosure by the U.S. Government is subject to
;;; restrictions set forth in FAR 52.227-19 (Commercial Computer
;;; Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
;;; (Rights in Technical Data and Computer Software), as applicable.
;;;
;;; ----------------------------------------------------------------
;;;
;;; This file contains a library of layer based routines. See individual
;;; routines for descriptions.
;;;
;;; External Functions:
;;;
;;; INIT_BONUS_ERROR --> AC_BONUS.LSP Intializes bonus error routine
;;; RESTORE_OLD_ERROR --> AC_BONUS.LSP restores old error routine
;;;


; -------------------- ISOLATE LAYER FUNCTION --------------------
; Isolates selected object's layer by turning all other layers off
; ----------------------------------------------------------------

(Defun C:LAYISO (/ SS CNT LAY LAYLST VAL)

(init_bonus_error
(list
(list "cmdecho" 1
"expert" 0
)
T ;flag. True means use undo for error clean up.
);list
);init_bonus_error

(if (not (setq SS (ssget "i")))
(progn
(prompt "\nSelect object(s) on the layer(s) to be ISOLATED: ")
(setq SS (ssget))
)
)

(if SS
(progn

(setq CNT 0)

(while (setq LAY (ssname SS CNT))
(setq LAY (cdr (assoc 8 (entget LAY))))
(if (not (member LAY LAYLST))
(setq LAYLST (cons LAY LAYLST))
)
(setq CNT (1+ CNT))
)

(if (member (getvar "CLAYER") LAYLST)
(setq LAY (getvar "CLAYER"))
(setvar "CLAYER" (setq LAY (last LAYLST)))
)

(command "_.-LAYER" "_OFF" "*" "_Y")
(foreach VAL LAYLST (command "_ON" VAL))
(command "")

(if (= (length LAYLST) 1)
(prompt (strcat "\nLayer " (car LAYLST) " has been isolated."))
(prompt (strcat "\n" (itoa (length LAYLST)) " layers have been isolated. "
"Layer " LAY " is current."
)
)
)
)
)

(restore_old_error)

(princ)
)

; -------------------- LAYER FREEZE FUNCTION ---------------------
; Freezes selected object's layer
; ----------------------------------------------------------------

(defun C:LAYFRZ ()
(layproc "frz")
(princ)
)

; ---------------------- LAYER OFF FUNCTION ----------------------
; Turns selected object's layer off
; ----------------------------------------------------------------

(defun C:LAYOFF ()
(layproc "off")
(princ)
)

; ------------- LAYER PROCESSOR FOR LAYOFF & LAYFRZ --------------
; Main program body for LAYOFF and LAYFRZ. Provides user with
; options for handling nested entities.
; ----------------------------------------------------------------

(defun LAYPROC ( TASK / NOEXIT OPT BLKLST CNT EN PMT ANS LAY NEST BLKLST)


; --------------------- Error initialization ---------------------

(init_bonus_error
(list
(list "cmdecho" 0
"expert" 0
)

nil ;flag. True means use undo for error clean up.
);list
);init_bonus_error

; -------------------- Variable initialization -------------------

(setq NOEXIT T)

(setq OPT (getcfg (strcat "AppData/AC_Bonus/Lay" TASK))) ; get default option setting
(if (not (or (null OPT) (= OPT ""))) (setq OPT (atoi OPT)))

(setq CNT 0) ; cycle counter


(while NOEXIT

(initget "Options Undo")
(if (= TASK "off")
(setq EN (nentsel &quot;\nOptions/Undo/<Pick an object on the layer to be turned OFF>: &quot;))
(setq EN (nentsel &quot;\nOptions/Undo/<Pick an object on the layer to be FROZEN>: &quot;))
)

; ------------------------- Set Options --------------------------

(While (= EN &quot;Options&quot;)
(initget &quot;No Block Entity&quot;)
(cond
((= OPT 1)
(setq PMT &quot;\nBlock level nesting/Entity level nesting/<No nesting>: &quot;)
)
((= OPT 2)
(setq PMT &quot;\nBlock level nesting/No nesting/<Entity level nesting>: &quot;)
)
(T
(setq PMT &quot;\nEntity level nesting/No nesting/<Block level nesting>: &quot;)
)
)
(setq ANS (getkword PMT))

(cond
((null ANS)
(if (or (null OPT) (= OPT &quot;&quot;))
(progn
(print ANS)
(setq OPT 3)
(setcfg (strcat &quot;AppData/AC_Bonus/Lay&quot; TASK) &quot;3&quot;)
)
)
)
((= ANS &quot;No&quot;)
(setq OPT 1)
(setcfg (strcat &quot;AppData/AC_Bonus/Lay&quot; TASK) &quot;1&quot;)
)
((= ANS &quot;Entity&quot;)
(setq OPT 2)
(setcfg (strcat &quot;AppData/AC_Bonus/Lay&quot; TASK) &quot;2&quot;)
)
(T
(setq OPT 3)
(setcfg (strcat &quot;AppData/AC_Bonus/Lay&quot; TASK) &quot;3&quot;)
)
)

(initget &quot;Options&quot;)
(if (= TASK &quot;off&quot;)
(setq EN (nentsel &quot;\nOptions/Undo/<Pick an object on the layer to be turned OFF>: &quot;))
(setq EN (nentsel &quot;\nOptions/Undo/<Pick an object on the layer to be FROZEN>: &quot;))
)
)

; ------------------------- Find Layer ---------------------------

(if (and EN (not (= EN &quot;Undo&quot;)))
(progn

(setq BLKLST (last EN))
(setq NEST (length BLKLST))

(cond

; If the entity is not nested or if the option for entity
; level nesting is selected.

((or (= OPT 2) (< (length EN) 3))
(setq LAY (entget (car EN)))
)

; If no nesting is desired

((= OPT 1)
(setq LAY (entget (car (reverse BLKLST))))
)

; All other cases (default)

(T
(setq BLKLST (reverse BLKLST))

(while (and ; strip out xrefs
( > (length BLKLST) 0)
(assoc 1 (tblsearch &quot;BLOCK&quot; (cdr (assoc 2 (entget (car BLKLST))))))
);and
(setq BLKLST (cdr BLKLST))
)
(if ( > (length BLKLST) 0) ; if there is a block present
(setq LAY (entget (car BLKLST))) ; use block layer
(setq LAY (entget (car EN))) ; else use layer of nensel
)
)
)

; ------------------------ Process Layer -------------------------

(setq LAY (cdr (assoc 8 LAY)))

(if (= LAY (getvar &quot;CLAYER&quot;))
(if (= TASK &quot;off&quot;)
(progn
(prompt (strcat &quot;\nReally want layer &quot; LAY &quot; (the CURRENT layer) off? <N>: &quot;))
(setq ANS (strcase (getstring)))
(if (not (or (= ANS &quot;Y&quot;) (= ANS &quot;YES&quot;)))
(setq LAY nil)
)
)
(progn
(prompt (strcat &quot;\nCannot freeze layer &quot; LAY&quot;. It is the CURRENT layer.&quot;))
(setq LAY nil)
)
)
(setq ANS nil)
)

(if LAY
(if (= TASK &quot;off&quot;)
(progn
(if ANS
(command &quot;_.-LAYER&quot; &quot;_OFF&quot; LAY &quot;_Yes&quot; &quot;&quot;)
(command &quot;_.-LAYER&quot; &quot;_OFF&quot; LAY &quot;&quot;)
)
(prompt (strcat &quot;\nLayer &quot; LAY &quot; has been turned off.&quot;))
(setq CNT (1+ CNT))
)
(progn
(command &quot;_.-LAYER&quot; &quot;_FREEZE&quot; LAY &quot;&quot;)
(prompt (strcat &quot;\nLayer &quot; LAY &quot; has been frozen.&quot;))
(setq CNT (1+ CNT))
)
)
)
)

; -------------- Nothing selected or Undo selected ---------------

(progn
(if (= EN &quot;Undo&quot;)
(if (> CNT 0)
(progn
(command &quot;_.u&quot;)
(setq CNT (1- CNT))
)
(prompt &quot;\nEverything has been undone.&quot;)
)
(setq NOEXIT nil)
)
)
)
)

(restore_old_error)

)

; --------------------- LAYER LOCK FUNCTION ----------------------
; Locks selected object's layer
; ----------------------------------------------------------------

(Defun C:LAYLCK (/ LAY)

(init_bonus_error
(list
(list &quot;cmdecho&quot; 0
&quot;expert&quot; 0
)

T ;flag. True means use undo for error clean up.
);list
);init_bonus_error

(setq LAY (entsel &quot;\nPick an object on the layer to be LOCKED: &quot;))

(if LAY
(progn
(setq LAY (cdr (assoc 8 (entget (car LAY)))))
(Command &quot;_.-LAYER&quot; &quot;_LOCK&quot; LAY &quot;&quot;)
(prompt (strcat &quot;\nLayer &quot; LAY &quot; has been locked.&quot;))
)
)

(restore_old_error)

(princ)
)

; -------------------- LAYER UNLOCK FUNCTION ---------------------
; Unlocks selected object's layer
; ----------------------------------------------------------------

(Defun C:LAYULK (/ LAY)

(init_bonus_error
(list
(list &quot;cmdecho&quot; 0
&quot;expert&quot; 0
)

T ;flag. True means use undo for error clean up.
);list
);init_bonus_error

(setq LAY (entsel &quot;\nPick an object on the layer to be UNLOCKED: &quot;))

(if LAY
(progn
(setq LAY (cdr (assoc 8 (entget (car LAY)))))
(Command &quot;_.-LAYER&quot; &quot;_UNLOCK&quot; LAY &quot;&quot;)
(prompt (strcat &quot;\nLayer &quot; LAY &quot; has been unlocked.&quot;))
)
)

(restore_old_error)

(princ)
)

; ---------------------- LAYER ON FUNCTION -----------------------
; Turns all layers on
; ----------------------------------------------------------------

(Defun C:LAYON ()

(init_bonus_error
(list
(list &quot;cmdecho&quot; 0)
nil ;flag. True means use undo for error clean up.
);list
);init_bonus_error

(Command &quot;_.-LAYER&quot; &quot;_ON&quot; &quot;*&quot; &quot;&quot;)
(prompt &quot;\nAll layers have been turned on.&quot;)

(restore_old_error)

(princ)
)


; --------------------- LAYER THAW FUNCTION ----------------------
; Thaws all layers
; ----------------------------------------------------------------

(Defun C:LAYTHW ()

(init_bonus_error
(list
(list &quot;cmdecho&quot; 0)
nil ;flag. True means use undo for error clean up.
);list
);init_bonus_error

(Command &quot;_.-LAYER&quot; &quot;_THAW&quot; &quot;*&quot; &quot;&quot;)
(prompt &quot;\nAll layers have been thawed.&quot;)

(restore_old_error)

(princ)
)


; --------------------- LAYER MATCH FUNCTION ---------------------
; Changes the layer of selected object(s) to the layer of a
; selected destination object.
; ----------------------------------------------------------------

(Defun C:LAYMCH (/ SS CNT LOOP LAY ANS)

(init_bonus_error
(list
(list &quot;cmdecho&quot; 0)
T ;flag. True means use undo for error clean up.
);list
);init_bonus_error


(if (not (setq SS (ssget &quot;i&quot;)))
(progn
(prompt &quot;\nSelect objects to be changed: &quot;)
(setq SS (ssget))
)
)

(if SS
(progn
(setq CNT (sslength SS))
(princ (strcat &quot;\n&quot; (itoa CNT) &quot; found.&quot;)) ; Report number of items found

(command &quot;_.move&quot; SS &quot;&quot;) ; filter out objects on locked layers

(if (> (getvar &quot;cmdactive&quot;) 0) ; if there are still objects left
(progn
(command &quot;0,0&quot; &quot;0,0&quot;)
(setq SS (ssget &quot;p&quot;)
CNT (- CNT (sslength SS)) ; count them
)
)
(setq SS nil) ; else abort operation
)

(if (> CNT 0) ; if items where filtered out
(if (= CNT 1)
(princ (strcat &quot;\n&quot; (itoa CNT) &quot; was on a locked layer.&quot;)) ; report it.
(princ (strcat &quot;\n&quot; (itoa CNT) &quot; were on a locked layer.&quot;))
)
)
)
)


(if SS
(progn
(initget &quot;Type&quot;)
(setq LAY (entsel &quot;\nType name/Select entity on destination layer: &quot;)
LOOP T
)

(while LOOP
(cond
((not LAY)
(prompt &quot;\nNothing selected.&quot;)
(prompt &quot;\nUse current layer? <Y> &quot;)
(setq ANS (strcase (getstring)))
(if (or (= ANS &quot;&quot;) (= ANS &quot;Y&quot;) (= ANS &quot;YES&quot;))
(setq LAY (getvar &quot;clayer&quot;)
LOOP nil
)
)
)
((listp LAY)
(setq LOOP nil)
)
((= LAY &quot;Type&quot;)
(setq LAY (getstring &quot;\nEnter layer name: &quot;))
(cond
((tblobjname &quot;LAYER&quot; LAY)
(setq LOOP nil)
)
((/= LAY &quot;&quot;)
(prompt &quot;\nLayer does not exist. Would you like to create it? <Y>: &quot;)
(setq ANS (strcase (getstring)))
(if (or (= ANS &quot;&quot;) (= ANS &quot;Y&quot;) (= ANS &quot;YES&quot;))
(if
(entmake (list
'(0 . &quot;LAYER&quot;)
'(100 . &quot;AcDbSymbolTableRecord&quot;)
'(100 . &quot;AcDbLayerTableRecord&quot;)
'(6 . &quot;CONTINUOUS&quot;)
'(62 . 7)
'(70 . 0)
(cons 2 LAY)
)
)
(setq LOOP nil)
(prompt &quot;\nInvalid Layer name.&quot;)
)
)
)
)
)
)
(if LOOP
(progn
(initget &quot;Type&quot;)
(setq LAY (entsel &quot;\nType name/Select entity on destination layer: &quot;))
)
)
); while LOOP


(if (listp LAY)
(setq LAY (cdr (assoc 8 (entget (car LAY)))))
)

(command &quot;_.change&quot; SS &quot;&quot; &quot;_p&quot; &quot;_la&quot; LAY &quot;&quot;)

(if (= (sslength SS) 1)
(prompt (strcat &quot;\nOne object changed to layer &quot; LAY ))
(prompt (strcat &quot;\n&quot; (itoa (sslength SS)) &quot; objects changed to layer &quot; LAY ))
)
(if (= LAY (getvar &quot;clayer&quot;))
(prompt &quot; (the current layer).&quot;)
(prompt &quot;.&quot;)
)
)
)

(restore_old_error)

(princ)
)

; --------------- CHANGE TO CURRENT LAYER FUNCTION ---------------
; Changes the layer of selected object(s) to the current layer
; ----------------------------------------------------------------

(Defun C:LAYCUR (/ SS CNT LAY)

(init_bonus_error
(list
(list &quot;cmdecho&quot; 0)
T ;flag. True means use undo for error clean up.
);list
);init_bonus_error


(if (not (setq SS (ssget &quot;i&quot;)))
(progn
(prompt &quot;\nSelect objects to be CHANGED to the current layer: &quot;)
(setq SS (ssget))
)
)

(if SS
(progn
(setq CNT (sslength SS))
(princ (strcat &quot;\n&quot; (itoa CNT) &quot; found.&quot;)) ; Report number of items found

(command &quot;_.move&quot; SS &quot;&quot;) ; filter out objects on locked layers

(if (> (getvar &quot;cmdactive&quot;) 0) ; if there are still objects left
(progn
(command &quot;0,0&quot; &quot;0,0&quot;)
(setq SS (ssget &quot;p&quot;)
CNT (- CNT (sslength SS)) ; count them
)
)
(setq SS nil) ; else abort operation
)

(if (> CNT 0) ; if items where filtered out
(if (= CNT 1)
(princ (strcat &quot;\n&quot; (itoa CNT) &quot; was on a locked layer.&quot;)) ; report it.
(princ (strcat &quot;\n&quot; (itoa CNT) &quot; were on a locked layer.&quot;))
)
)
)
)

(if SS
(progn
(setq LAY (getvar &quot;CLAYER&quot;))
(command &quot;_.change&quot; SS &quot;&quot; &quot;_p&quot; &quot;_la&quot; LAY &quot;&quot;)
(if (= (sslength SS) 1)
(prompt (strcat &quot;\nOne object changed to layer &quot; LAY &quot; (the current layer).&quot;))
(prompt (strcat &quot;\n&quot; (itoa (sslength SS)) &quot; objects changed to layer &quot; LAY &quot; (the current layer).&quot;))
)
)
)

(restore_old_error)

(princ)
)

(prompt &quot;\nAutoCAD Bonus Layer Tools Loaded.&quot;)
(princ)
******************************* Pardal
 
Replies continue below

Recommended for you

Pardal,

Try this:

Change the 'off' line to this:
(command &quot;.-layer&quot; &quot;_F&quot; &quot;*&quot;)

this freezes all layers except the current one. Then change next line to:

(foreach VAL LAYLST (command &quot;_THAW&quot; VAL))

This thaws all layers for which you have selected items.

Cheers,
Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor