+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Senior Member
    Using
    Inventor 2013
    Join Date
    Feb 2006
    Location
    England (Leeds)
    Posts
    305

    Default Is there a LISP to toggle layers?

    Registered forum members do not see this ad.

    Hi,

    I am after a lisp or script that toggles layers in autocad by just clicking 1 button - similar to the way you go back & forward using the internet explorer arrows. Does anyone know if this can be done? (newb here!)

    My layers are as follows:-

    PAGE001
    PAGE002
    PAGE003 etc..

    So for example, I am on layer PAGE001 (which is a drawing on its own), I want to go to layer PAGE002, at the moment I have to thaw PAGE002, make PAGE002 'current' then 'freeze; PAGE001

    All this is time consuming when you have PAGE001 TO PAGE100 and have to modify each drawing. I tried google to find a solution but have had no luck.

    Any help would be great, thanks for reading,

    Ste

  2. #2
    Super Member
    Using
    AutoCAD 2007
    Join Date
    Aug 2003
    Location
    Livingston, Scotland
    Posts
    995

    Default

    that isn't toggling, that is stepping.
    Toggling would be reversing the current layer visibility states, for example, if you had layers 1, 2 and 3 with layer 1 on and 2 & 3 frozen, then toggling would thaw layers 2 & 3 and freeze layer1

    I think what you are looking for is the LAYWALK command.. which is already a part of AutoCAD
    ResourceCAD.... the Resource for your CAD Solutions

  3. #3
    Super Moderator fuccaro's Avatar
    Discipline
    Mechanical
    fuccaro's Discipline Details
    Occupation
    Mechanical eng.
    Discipline
    Mechanical
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,577

    Default

    If you wish to do it yourself:
    Be sure that the folowing code is loaded and assign the command (nextlay) to a button.
    Code:
    (defun nextlay( / n l);next layer
      (setq n (cdr (assoc 2 (if (setq l (tblnext "layer")) l (tblnext "layer" t)))))
      (command "-layer" "t" n "s" n "f" "*" "")
      )
    It's nice to be nice, but sometimes is nicer to be evil!
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  4. #4
    Senior Member
    Using
    Inventor 2013
    Join Date
    Feb 2006
    Location
    England (Leeds)
    Posts
    305

    Default

    Thanks guys for your time.

    I pasted the code into notepad, renamed it 'nextlay.lsp' and loaded it in AutoCAD, but when I type 'nextlay' nothing happens! What am I doing wrong?

  5. #5
    Senior Member
    Using
    Inventor 2013
    Join Date
    Feb 2006
    Location
    England (Leeds)
    Posts
    305

    Default

    Sorry Hendie, thanks for your patience!

  6. #6
    Full Member
    Using
    not specified
    Join Date
    Aug 2006
    Posts
    31

    Default

    put a c: before the nextlay in the code..
    that how you can run the lisp command from command prompt!
    India CAD, The CAD people
    http://indiacad.11.forumer.com/

  7. #7
    Super Moderator fuccaro's Avatar
    Discipline
    Mechanical
    fuccaro's Discipline Details
    Occupation
    Mechanical eng.
    Discipline
    Mechanical
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,577

    Default

    enter (nextlay) in the command line, or edit the source code as India says.
    It's nice to be nice, but sometimes is nicer to be evil!
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  8. #8
    Senior Member
    Using
    Inventor 2013
    Join Date
    Feb 2006
    Location
    England (Leeds)
    Posts
    305

    Default

    Thanks guys. It works now. Really appreciate your help!

    Ste

  9. #9
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Dec 2007
    Posts
    93

    Default

    This thread is disappointing (because I do want to toggle layers).

    I want to be able to assign a button (probably will assign a hotkey) to a function that toggles a specific layer on and off. For example, we use an IMAGE layer as a backdrop to digitize features a lot. It would be nice to toggle that fast without using the layer drop down. Doesn't seem like much, but saving those 3 clicks over and over again really would speed up editing.

    I'm not sure how to do the If, then to detect what layers are on or off though.

    Anyone have a toggle function? I would prefer one that hard codes the layer name (that can be changed in the code easily). Thanks.

  10. #10
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Dec 2007
    Posts
    93

    Default

    Registered forum members do not see this ad.

    I decided I'll just assign a hotkey to on and a hotkey to off for now. It's easy enough.

    (defun IMAGEoff ()
    (command "-layer" "OFF" "IMAGE" "")
    )

    (defun IMAGEon ()
    (command "-layer" "ON" "IMAGE" "")
    )

Bookmarks

Posting Permissions

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