Layerstate Restore from command line

Is it possible to create a lisp routine that can restore a layer state without opening the Drawing Explorer?
I would like to be able to type LS and then CLG and see the ceiling plan layer state.
Or, better still, embed the name of a layer state in each of several similar lisp routines, and just type LS2 to restore the layer state named in that routine.


  • A lisp-less alternative:

    Key in CUI to open the customize dialog, and select the Toolbars tab.
    In the left column, select the Entity Properties toolbar and click on the '+' sign next to it to see its content.
    In the right column, scroll to the bottom and open the Controls section.
    Drag the LayerState combo control into the Entity Properties toolbar.
    Click the OK button to close the dialog.

    You now can change to the desired layerstate by selecting it in your Entity Properties toolbar.

  • Terrific! I never knew about that. Thanks.

  • Excellent, Hans. Thank you for this tip.

    I never knew this control existed. I will publish this tip to our users here.

    Best Regards
  • If for some reason you do want to create a Lisp function you should be aware that the -LAYER command can be used for layer states.
  • Ah, that's what I was looking for... -LAYER, not -LAYERSTATE. Thanks, Roy.

    I actually did make the lisp routines I described above. It was about 20 years ago, and when I tried to re-create them I was trying to find a command-line version of LAYERSTATE, and of course I couldn't. I should have been looking at -LAYER.

    That new pull-down method of restoring layer state is better under normal working conditions, but I will re-create those lisp routines for use on the bus. I often work 4 hours a day on a bus, where the vibration makes mouse work very difficult. So in that situation doing things by use of the keyboard is preferable.
  •  I am still trying to make the LIPS routine for Layerstates. So far I am clueless why this simple line does not work:
    (DEFUN C:ele nil (command “layer” “a” “r” “ele” “” “”))
    The response I get is "nil" and nothing happens. I can make it work by typing -layer etc. 
    I would appreciate any help here. 
    I am running v15.3.07 on MacOS. 

  • Dear Marek,

    the (command...) function always returns NIL, by definition ... it does not indicate whether the intended command sequence was successful or not.
    Just a hint : always use English notation for commands and options in (command...) sequences ...
    also a good behaviour : use fully specified options ... sometimes there are tiny differences in option keys compared to AutoCAD;
    also, it is easier to understand what the code makes ...

    (defun c:ele ()
      (command "_layer" "_state" "_restore" ...")

    maybe it will work on V16 for OSX ? Likely there were some fixes from V15 to V16 here ...
    many greetings !
  •  Dear Torsten,
    thanks for a super quick reply. It did help a bit but still the command seems to stop at the name of the layer state...  So just to be sure: it should be "ele" and then 2x "" to terminate the command?
    I will give it another try at one of the V16 Windows machines when back in the office. 
    Big thanks, Marek
  • Hello.

    Why not use the Layerstate-Controlbar?
    Since V16 it works fine even with layerstates with vpcolor-settings (on windows though...)
    It works as good in model as it does in viewports.


  • Dear Marek,
    you can check if CMDECHO=1 when your Lisp code runs ... then you will see when command sequence runs "out-of-sync" ...
    also, does same sequence work manually, using _-LAYER command ?
    many greetings !
  • @Sascha,
    Re: Why not use the Layerstate-Controlbar? 
    the control bar is very nice. I guess 9 out of 10 people in the office will be using it. Unfortunately I am the 1 in 10 that old enough to prefer the text commands. 
    yes, the command works manually. 
    yes, I have the CMDECHO=1. All that happens is the command line goes through _layer, then _state, then _restore and then you can see a blank field with the state name. As if the name was not input into the line. 

    Well, I've written all this and still experimented. Then suddenly one of the commands started working. I started comparing and I found a mean bug - while editing in MacOs edit any " was being changed to " in italics. The same symbol but not to Brics. When I changed all the " to straight ones everything is working like a charm now!

    The lesson - be careful when editing text in MacOS text edit. The program outsmarts you without showing!

    Big thanks for all the help!
  • Dear Marek,

    arrrgs - funny "bug" ...
    indeed, Lisp code files (as any other of the textual customisation files) are declared to be ANSI -
    AutoCAD as well only supports UTF-8, in best case (but for example, not for Lisp code files, to my knowledge) ...

    So you can configure your editor to store ANSI, for safety ...
    many greetings !
  •  Yep :-)
    Actually you can even see " in italics in my first post! I do like Mac but sometimes it goes a bit over the top ;-)
    Best regards!
This discussion has been closed.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!