Results 1 to 5 of 5

Thread: An old but useful lsp - Layer Manipulation (All layers on)

  1. #1
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default An old but useful lsp - Layer Manipulation (All layers on)

    This lsp allows you to turn on and tahw all layers, do work and restore the layer state.
    (I know I can make a layer state each time, but this is so much easier)
    I am open to suggestions and please let me know if Acad already has something like this somewhere.

    The lsp does the following
    -Creates a layer state with a specific name
    -Turns on and thaws all layers
    -Sets up so next time you enter the command it will restore your layer state.

    I created this lisp several years ago and I loved it, just changed positions and needed to recreate the routine.

    Code:
    (princ "\nThaw_or_Restore.lsp type \"LOT\" to begin command\n")
    
    (defun c:lot (/ lsname othaw_or_restore)
      (if (not thaw_or_restore) (setq thaw_or_restore "thaw"))
      (setq othaw_or_restore thaw_or_restore)
    
      (if
        (= othaw_or_restore "thaw")
        (thawall))
      (if
        (= othaw_or_restore "restore")
        (thawrestore))
      (princ))
      
      
    
    (defun thawall (/ lsname)
      (command "undo" "begin")
      (setq lsname "thaw_and_restore")
      (if (=
    	(command ".layer" "state" "save" lsname "" "" "")
    	nil)
        (progn
          (command ".layer" "state" "delete" lsname "" "" "")
          (command ".layer" "state" "save" lsname "" "" "")
          )
        )
      (command ".layer" "state" "save" lsname "" "" "")
      (command "-layer" "thaw" "*" "" "")
      (command "-layer" "on" "*" "" "")
      (setq thaw_or_restore "restore")
      (graphscr)
      (command "undo" "end")
      (princ "\nall layers on and thawed")
      (princ))
    
    (defun thawrestore (/ lsname)
      (command "undo" "begin")
      (setq lsname "thaw_and_restore")
      (command ".layer" "state" "restore" lsname "" "" "")
      (command ".layer" "state" "delete" lsname "" "" "")
      (setq thaw_or_restore "thaw")
      (graphscr)
      (command "undo" "end")
      (princ "\nlayer state restored")
      (princ))
    Attached Files Attached Files
    Last edited by ReachAndre; 2012-02-15 at 01:44 PM.

  2. #2
    Member
    Join Date
    2009-03
    Posts
    7
    Login to Give a bone
    0

    Default Re: An old but useful lsp - Layer Manipulation (All layers on)

    should be useful
    cheers!

  3. #3
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default Re: An old but useful lsp - Layer Manipulation (All layers on)

    Quote Originally Posted by pbourke View Post
    should be useful
    cheers!
    Glad you like it

  4. #4
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,658
    Login to Give a bone
    0

    Default Re: An old but useful lsp - Layer Manipulation (All layers on)

    Cool! I shortened it with a few newer commands...
    Code:
     (defun c:LayAll (/ CMD lsname)
      (setq CMD (getvar "Cmdecho"))
      (setvar "Cmdecho" 0)
      (setq lsname "Off_or_Frozen")
      (if (layerstate-has lsname)
        (progn
          (layerstate-restore lsname nil nil)
          (princ "\nOff or Frozen layers restored")
          (layerstate-delete lsname)
        )
        (progn
          (layerstate-save lsname nil nil)
          (command "layon" "laythw")
        )
      )
      (setvar "Cmdecho" CMD)
      (princ)
    )

  5. #5
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: An old but useful lsp - Layer Manipulation (All layers on)

    My versions:
    Code:
    (vl-load-com)
    
    (defun LayAll (stateName properties / doc)
      (vla-StartUndoMark (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))
      (if (layerstate-has stateName)
        (progn
          (layerstate-restore stateName nil)
          (layerstate-delete stateName))
        (progn
          (layerstate-save stateName 3 nil)
          (vlax-for layer (vla-get-Layers doc)
            (foreach prop properties
              (vl-catch-all-apply (car prop) (list layer (cdr prop)))))))
      (vla-EndUndoMark doc))
    
    (defun c:LAT  (/)
      (LayAll "_Layer_All_Thaw" '((vla-put-Freeze . :vlax-false)))
      (princ))
    
    (defun c:LAO  (/)
      (LayAll "_Layer_All_On" '((vla-put-LayerOn . :vlax-true)))
      (princ))
    
    (defun c:LATO  (/)
      (LayAll "_Layer_All_Thaw_On" '((vla-put-LayerOn . :vlax-true) (vla-put-Freeze . :vlax-false)))
      (princ))
    Doesn't use commands - so no need for the cmdecho.

Similar Threads

  1. Layer Manipulation Help
    By CADdancer in forum AutoLISP
    Replies: 5
    Last Post: 2010-11-22, 07:22 PM
  2. Layer Manipulation thru Xref's...
    By ameador in forum AMEP General
    Replies: 5
    Last Post: 2008-06-09, 02:20 PM
  3. Layer manipulation - VBA challenge
    By nicolae.baboi in forum VBA/COM Interop
    Replies: 5
    Last Post: 2007-04-23, 02:41 PM
  4. Layer manipulation routine...
    By bhansen.114377 in forum AutoLISP
    Replies: 2
    Last Post: 2006-09-19, 08:59 PM
  5. ActiveX API - Layer Filter Manipulation
    By ntaylor in forum API Wish List
    Replies: 6
    Last Post: 2004-09-08, 10:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •