Lee Mac Posted December 23, 2008 Share Posted December 23, 2008 Not quite sure why the "program shortcut" part is there either. I added the program shortcut as I wanted to call my function "erase_all" or a sensible name that someone could relate to, but I didn't want the user to have to type "erase_all" everytime they ran the LISP, so I added a "program shortcut", where the user only has to type "ea" to run the LISP. Some great help there from Dave, nice one. Scripts are useful, (not that I have created one myself, so I am not too confident with them) but I have used one before to perform some batch plotting to PDF. The LISP I provided contains a lot of command calls, so a script would probably be more appropriate - but as Dave says, the script files are slightly more elusive than LISP. You need to go into load application and add it to the startup suite. You can add the LISP to the startup-suite, or a more reliable method would be to add a call for the LISP in the ACADDOC.lsp file. I have to say that the code is a lot more complicated than i thought it would be. I must admit, I have made it slightly more complicated than it could be by adding an error handler (in case something goes wrong!)... Now i've got a taste for some advanced stuff it's really whetted my appetite for what AutoCAD can do. I'm thinking of getting the AutoCAD Bible to increase my meager knowledge. There is some great material to learn from out there, but I must admit, I have learnt most from here on the forums - just analysing the LISP posts and how people structure their code is great to learn from. Nearly there but the file is saved as .dwg.dxf because the function I used to get the name includes the file extension. I also added a part to unlock all layers because the "cutting" layer was left locked at the end of the function. I'll take I quick look at your LISP and see what I can do Ok, thats all for now - nearly xmas people! Merry Christmas and Happy New Year everyone! Cheers Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 23, 2008 Share Posted December 23, 2008 Ok try this: (defun c:test () (command "_saveas" "DXF" "12" pause) (princ) ) ;_ end defun (defun c:ea () (c:erase_all)) ; Program Shortcut (defun c:erase_all (/ *error* varlist oldvars laylist ss str len name) (defun *error* (msg) ; Error Trap (mapcar 'setvar varlist oldvars) (if (= msg "") (princ "\nFunction Complete.") (princ "\nError or Esc Pressed...") ) ;_ end if (princ) ) ;_ end defun (setq varlist (list "CMDECHO" "CTAB" "CLAYER") oldvars (mapcar 'getvar varlist) ) ;_ end setq (setvar "cmdecho" 0) (if (not (tblsearch "LAYER" "tool path")) (command "-layer" "M" "tool path" "") ) ;_ end if (setq laylist (layoutlist)) (foreach x laylist (command "-layout" "D" x) ) ;_ end foreach (setvar "ctab" "MODEL") (command "-layer" "LO" "tool path" "") (setq ss (ssget "X" (list (cons 410 "MODEL")))) (command "_erase" ss "") (command "-purge" "A" "*" "N") (command "_audit" "Y") (command "_.Layer" "unlock" "*" "") (setq str (strlen (getvar "dwgname"))) (setq len (- str 4)) (setq name (substr (getvar "dwgname") 1 len)) (command "_.saveas" "DXF" "12" (strcat "c:\\" name)) (*error* "") ; Force error to reset variables. (princ) ) ;_ end defun (untested) Quote Link to comment Share on other sites More sharing options...
dbgeek Posted December 23, 2008 Share Posted December 23, 2008 Thanks it works perfectly. I'll have to look at what you did but at a glance it looks like you removed the last 4 letters. Quote Link to comment Share on other sites More sharing options...
wannabe Posted December 23, 2008 Share Posted December 23, 2008 I mentioned startup suite based upon my own experience of certain folders being access restricted. As above, its best if you add to a default folder where CAD looks anyway. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 23, 2008 Share Posted December 23, 2008 Excellent, glad it works for you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.