Help with lisp routine to modify layfrz.

Discussion in 'AutoCAD' started by JamieLandmark, Mar 22, 2005.

  1. Hello all,

    I would appreciate some help on a lisp routine that would do the following:

    1. Store the current layer.
    2. Set layer "0" as current.
    3. Call up layfrz.
    4. Restore the current layer.

    An alternative would be to:

    1. Call up layfrz.
    2. Call up -layer to thaw layer "0".

    The goal is to disallow layfrz from affecting the "0" layer. If someone can visualize the easiest method - I would appreciate the insight.

    Thank you,

    Jamie
     
    JamieLandmark, Mar 22, 2005
    #1
  2. JamieLandmark

    Josh Guest

    1. Make a backup of and open acetlayr.lsp in the Express folder
    2. Find the following line:
    ; ------------------------ Process Layer -------------------------

    3. Look a few lines down to find the following section:
    (if LAY
    (cond
    ((= TASK "off")
    (if ANS
    (command "_.-LAYER" "_OFF" LAY "_Yes" "")
    (command "_.-LAYER" "_OFF" LAY "")
    )

    4. Change to the following:
    (if LAY
    (cond
    ((and (= LAY "0")(or (= TASK "off")(= TASK "frz")))
    (prompt (strcat "\nLayer 0 cannot be " (if (= TASK "off")
    "turned off" "frozen") "."))
    )
    ((= TASK "off")
    (if ANS
    (command "_.-LAYER" "_OFF" LAY "_Yes" "")
    (command "_.-LAYER" "_OFF" LAY "")
    )

    I just did this a moment ago after reading your post (been on my to-do list
    for a while) and haven't tested it to any extent but it's acting okay so
    far...personally, I'm adding DEFPOINTS to the list, too.

    Josh



    can visualize the easiest method - I would appreciate the insight.
     
    Josh, Mar 22, 2005
    #2
  3. JamieLandmark

    Jeff Mishler Guest

    One easy way would be to add a bit of code to your acad.dvb file that would
    trigger on the CommandEnded Event. I know this can be done in lisp, but I
    don't use reactors in lisp to be able to code it. But here's all you would
    need for the VBA counterpart:

    Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
    If ThisDrawing.Layers.Item("0").Freeze = True Then
    ThisDrawing.Layers.Item("0").Freeze = False
    MsgBox "Layer 0 cannot be frozen! It has been reset to thawed." & vbCrLf
    & _
    "Thank you for cooperating. Have a nice day!", , "Invalid use of
    Freeze"
    ThisDrawing.Regen acAllViewports
    End If
    End Sub
     
    Jeff Mishler, Mar 22, 2005
    #3
  4. Hey Josh,

    How's the routine working for you so far? Any bugs?

    I'm eager to implement it, but am wary of it crashing my computer. An isolate layers lisp routine I've been using did this recently to my machine.

    Regards,

    Jamie
     
    JamieLandmark, Mar 23, 2005
    #4
  5. Hey Jeff,

    Thanks for the suggestion.

    My VBA is nonexistant. How would you go about adding defpoints to the affected layers?

    How do I use your code - is it similar to lisp?

    Thanks for your insight,

    Jamie
     
    JamieLandmark, Mar 23, 2005
    #5
  6. JamieLandmark

    Josh Guest

    No problems...works just fine for me. It's very useful since I have so many
    blocks that were created on layer 0. The code I added to layfrz wouldn't,
    in and of itself, crash a machine.

    isolate layers lisp routine I've been using did this recently to my machine.
     
    Josh, Mar 23, 2005
    #6
  7. Hey Josh,

    Thanks for testing it out. I'll implement it.

    I appreciate your help,

    Jamie
     
    JamieLandmark, Mar 24, 2005
    #7
  8. JamieLandmark

    Tom Smith Guest

    You've gotten some complicated solutions -- I'm surprised nobody suggested simply doing just what you described, step by step:

    (defun c:lf (/ clayer)
    (setq clayer (getvar 'clayer))
    (setvar 'clayer "0")
    (c:layfrz)
    (setvar 'clayer clayer)
    (princ))

    The modification to the supplied lisp should work, but I make it a practice not to do that. The routine above would accomplish the same thing.
     
    Tom Smith, Mar 24, 2005
    #8
  9. JamieLandmark

    Jeff Mishler Guest

    What happens if the user freezes the layer stored as clayer? Oops, now we
    show an error and get left on layer 0.......
     
    Jeff Mishler, Mar 24, 2005
    #9
  10. JamieLandmark

    Tom Smith Guest

    OP didn't speculate on that possibility, but being left on the one layer which isn't supposed to ever be frozen wouldn't seem to be a problem. Sunds more like an automatic feature -- you can freeze everything in the world but 0, and then you'll be left on 0.

    If you didn't want to see the harmless error message, one more line could prevent it from happening:

    (defun c:lf (/ clayer)
    (setq clayer (getvar 'clayer))
    (setvar 'clayer "0")
    (c:layfrz)
    (if (not (zerop (logand 1 (cdr (assoc 70 (tblsearch "layer" clayer))))))
    (setvar 'clayer clayer))
    (princ))
     
    Tom Smith, Mar 24, 2005
    #10
  11. Josh,

    Thanks again for your help. I just finished implementing the change, and it works just as I'd hoped :)

    If you have the time, could you tell me how to have the routine work with defpoints as well?

    Thanks a bunch,

    Jamie
     
    JamieLandmark, Mar 24, 2005
    #11
  12. Hey Tom,

    Thanks a lot for replying, but I've already gone with Josh's suggestion.

    I'm not sure if it's the best way, but it works great.

    Thanks again,

    Jamie
     
    JamieLandmark, Mar 24, 2005
    #12
  13. JamieLandmark

    Tom Smith Guest

    No problem. I mainly wanted to point out, if you're new to lisp, that your original clear description could easily be translated almost literally into a short lisp routine.

    You stated the program outline very clearly, which is always an important step, and it turns out that each step you listed can be done with a single function call. Maybe you can apply this to other tasks -- saving and restoring a layer is a very common thing.

    There's nothing really wrong with modifying Express Tools routines, but I make it a practice to avoid modifying anything that came "out of the box." Because by long experience I've seen how hard it is to keep track of every little change you've made over time, so that you can drag them all into another version when you upgrade. The longer between upgrades, the harder this is. I prefer to make all the customizations "in addition to" rather than "instead of" the supplied stuff. For instance if I have a different version of a supplied file, I place it in a custom folder earlier on the path, so Acad finds my version first. Upgrades are a whole lot easier if all your custom stuff is segregated from the supplied stuff.
     
    Tom Smith, Mar 24, 2005
    #13
  14. Hey Tom,

    First of all, I'd better give credit where credit is due. Martin Shoemaker over in the Express Tools group outlined the approach - so kudos to him.

    I see your point about modifying what comes out of the box. I've been upset before by modifications I've made to the .mns. I'll think twice before messing with it.

    Regards,

    Jamie
     
    JamieLandmark, Mar 24, 2005
    #14
  15. JamieLandmark

    Tom Smith Guest

    I don't avoid customizations, I just keep them separate! :)

    For example, I have I a custom folder tree which mimics the organization of the supplied folders -- support, plotters, template, etc. In some cases, like templates, I put our folder on the path instead of the standard one, so the users only see our drawing templates. The Acad supplied ones are sitting there unused, though you could browse to them if you needed to. In other cases, like support, I put our folder on the search path earlier than the standard one. That way, if I have a custom file by the same name as a standard one, mine will take precedence. If not, then the standard one will be found and used.

    The main point is, I never change any file supplied by Acad in its standard location, though I may modify a clone of it in another location. Everything that is custom is in a folder tree of its own, so I never have to track down anything when ity's time to upgrade -- just adjust the new version's search paths to include the custom folders, and I'm done.
     
    Tom Smith, Mar 24, 2005
    #15
  16. JamieLandmark

    Josh Guest

    Jamie,
    Adding the Defpoints layer is relatively simple...

    Find this section we've already modified:
    (if LAY
    (cond
    ((and (= LAY "0") (or (= TASK "off")(= TASK "frz")))
    (prompt (strcat "\nLayer 0 cannot be " (if (= TASK "off") "turned
    off" "frozen") "."))
    )

    And replace it with the following
    (if LAY
    (cond
    ((and (or (= LAY "0")(= (strcase LAY) "DEFPOINTS")) (or (= TASK
    "off")(= TASK "frz")))
    (prompt (strcat "\nLayer " LAY " cannot be " (if (= TASK "off")
    "turned off." "frozen.")))
    )

    To reiterate what Tom said, make sure you place this modified file OUTSIDE
    of your Autocad folder tree and place it in a folder that is higher than the
    Express folder in the support paths. I've modified several Autocad files to
    get what I want and each is placed safely in a folder on our network. Oh,
    always make a backup of any file before you do anything!

    ~Josh
     
    Josh, Mar 24, 2005
    #16
  17. Hey Tom,

    Sounds cool :)

    So you define which .mns AutoCAD finds first? You do this in the folder tree in options?

    I've been mystified as to which .mns is loaded first if I have more than one with the same name in the paths that AutoCAD is looking at. Does it just go from top to bottom?

    The way you work with AutoCAD is the way I want to. I don't want to mess with AutoCAD's standard stuff, and to have my customizations treated separately. I could avoid headaches when re-installing, etc.

    Regards,

    Jamie
     
    JamieLandmark, Mar 24, 2005
    #17
  18. Hey Josh,

    Thanks, man, I really appreciate your help and advice :)

    Jamie
     
    JamieLandmark, Mar 24, 2005
    #18
  19. JamieLandmark

    Tom Smith Guest

    Jamie, this kind of approach has been discussed at length in here. Most people who have gone through a number of version changes, supporting multiple users, eventually come to the same conclusions. Mark Middlebrook has written at length about it, and I highly recommend his article "Elegant AutoCAD customization eliminates problems" at http://www.cadalyst.com/cadalyst/article/articleDetail.jsp?id=80817

    As far as menus, I have no problem with allowing the standard Acad menu to be the "base" menu, loaded via the MENU command. I don't touch this. I also let the Express Tools partial menu load, via its normal process. For our office customizations, I do what the Express Tools do -- load an additional partial menu, via the MENULOAD command. Our custom partial menu includes a couple of pulldowns, a few toolbars, and several image menus called from the pulldowns, in addition to the standard Acad stuff.. Its associated mnl file actually initializes the rest of our setuo and autoloads all our custom lisps. I also provide an additional "user" partial menu, which individuals are free to customize any way they like, if they care to learn to do it.

    Since "our" menu stuff is completely sergregated from the Acad menu, when we changed versions last (A2Ki to A2K4) all I had to do was set the search paths to include our customizations, then MENULOAD our custom partial. The whole works came over from one version to the next without a hitch. Then I exported that profile, which includes all the settings including the menuload. To set up a new workstation, I do a standard Acad install, accept all the defaults, then import that profile and walk away. It takes only a few seconds, and there's no hand-tweaking to do.
     
    Tom Smith, Mar 25, 2005
    #19
  20. JamieLandmark

    Josh Guest

    You're quite welcome.
     
    Josh, Mar 25, 2005
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.