matma7 Posted December 22, 2008 Share Posted December 22, 2008 Hello Everyone, I stumbled across this website a while ago and regularly browsed it whilst I’m on my lunch break. I'd call myself a light CAD user as I do simple 2D fabrication drawings. I'm an avid world of warcraft player and have just started making macros for my various toons. I wondered whether I could make some for AutoCAD and it turns out that you can. I'm totally lost - this is what I want to do: Delete layouts Switch back to model space Lock layer (this will always be called LINTEL) Select all Erase Purge (yes to all - do not verify) Audit (Yes fix all errors) I do this about 20 times per day when putting Parts on the Laser profiler. I could save up to 20 minutes with this macro. Can anyone help me out with this. Kind regards Matt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 22, 2008 Share Posted December 22, 2008 First off, Welcome to CADTutor, hope you like it here I would approach this problem with LISP or VBA as opposed to a macro approach - it will make it far simpler and still achieve the desired result. I'll see what I can come up with Quote Link to comment Share on other sites More sharing options...
matma7 Posted December 22, 2008 Author Share Posted December 22, 2008 Cool, Thanks for your quick responce. You seem to be quite the helper on here! :) I'm no expert (pretty much self taught) but i might be able to help out in beginner forum. Regards Matt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 22, 2008 Share Posted December 22, 2008 Well, whatever help you can provide, I'm sure it will be appreciated *Almost finished your LISP* Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 22, 2008 Share Posted December 22, 2008 This should do the trick: (defun c:ea () (c:erase_all)) ; Program Shortcut (defun c:erase_all (/ *error* varlist oldvars laylist ss) (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" "LINTEL")) (command "-layer" "M" "LINTEL" "") ) ;_ end if (setq laylist (layoutlist)) (foreach x laylist (command "-layout" "D" x) ) ;_ end foreach (setvar "ctab" "MODEL") (command "-layer" "LO" "LINTEL" "") (setq ss (ssget "X" (list (cons 410 "MODEL")))) (command "_erase" ss "") (command "-purge" "A" "*" "N") (command "_audit" "Y") (*error* "") ; Force error to reset variables. (princ) ) ;_ end defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 22, 2008 Share Posted December 22, 2008 You seem to be quite the helper on here! I try my best, I'm still learning to be honest - my Visual LISP knowledge is lacking big time... but there are so many knowledgeable and helpful guys on here, it makes learning pretty easy. Quote Link to comment Share on other sites More sharing options...
matma7 Posted December 22, 2008 Author Share Posted December 22, 2008 Wow, thanks man. That was super quick. when i first posted i thought it might take several days to get a reply. I really appreciate your help! Kind Regards Matt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 22, 2008 Share Posted December 22, 2008 No probs Matt, Hope it all works for you. If you have any further queries or questions let me know; also, if you need help saving, loading or running the LISP, the FAQ is probably the first place to look, and if you are still perplexed just give us a shout. Cheers, Lee Quote Link to comment Share on other sites More sharing options...
MaxwellEdison Posted December 22, 2008 Share Posted December 22, 2008 It would take several days, except Lee wrote a LISP routine which removes the necessity for him to sleep. As soon as he completes his Man Machine Interface LISP and Super Relativity LISP he'll actually be able to write the LISP before you even think to ask for it. So when LISPs randomly begin opening in your drawing, be sure to come back here and thank him. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 22, 2008 Share Posted December 22, 2008 It would take several days, except Lee wrote a LISP routine which removes the necessity for him to sleep. As soon as he completes his Man Machine Interface LISP and Super Relativity LISP he'll actually be able to write the LISP before you even think to ask for it. So when LISPs randomly begin opening in your drawing, be sure to come back here and thank him. haha, Damn you're onto me... Quote Link to comment Share on other sites More sharing options...
dbgeek Posted December 23, 2008 Share Posted December 23, 2008 Nice. I program Lasers and Plasmas and I have written a autohotkey script to do this. A lisp solution would be a cleaner solution but for some reason I never thought of using lisp Thanks Lee Mac I will use your script for inspiration. I had a quick search and could not find a way to saveas in lisp what I want to do is save the dwg as a dxf in a different folder after it has been striped down. any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
dbgeek Posted December 23, 2008 Share Posted December 23, 2008 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. (defun c:ea () (c:erase_all)) ; Program Shortcut (defun c:erase_all (/ *error* varlist oldvars laylist ss) (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" "*" "") (command "_.saveas" "DXF" "12" (strcat "c:\\dxf\\" (getvar "dwgname")) ) (*error* "") ; Force error to reset variables. (princ) ) ;_ end defun Not quite sure why the "program shortcut" part is there either. Quote Link to comment Share on other sites More sharing options...
matma7 Posted December 23, 2008 Author Share Posted December 23, 2008 After reading the FAQ's lastnight i came into work today, loaded up the Lisp and it works perfectly. I didnt have any doubt about code but was my ability to implement it. I have to say that the code is a lot more complicated than i thought it would be. I was originally trying to copy text from the command line as they would appear if i had carried them out. 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. Once again thanks Lee for your help! One last question - Is it possible to have the Lisp always loaded. ie. saved into a template or does it require loading each time? Quote Link to comment Share on other sites More sharing options...
wannabe Posted December 23, 2008 Share Posted December 23, 2008 You need to go into load application and add it to the startup suite. Quote Link to comment Share on other sites More sharing options...
dbroada Posted December 23, 2008 Share Posted December 23, 2008 now that Lee has given you an elegant solution I can say "I wouldn't have done it that way". For something like this I would write a script. For those of you with 2009 there is a built in script editor (I haven't tried it yet) but for older versions you just need notepad. If you have a sequence you are always repeating scripts are brilliant. (we do all our batch plotting using scripts) Check out the help file or browse this forum - there are many examples of scripts. Quote Link to comment Share on other sites More sharing options...
dbgeek Posted December 23, 2008 Share Posted December 23, 2008 For something like this I would write a script. What kind of script? What's wrong with lisp? Quote Link to comment Share on other sites More sharing options...
dbroada Posted December 23, 2008 Share Posted December 23, 2008 nothing wrong with LISP. In this case it is an elegant solution that took Lee only a little while to write. I'm just offering an alternative solution, especially helpful if you have no programming knowledge. the type of script I would use is an AutoCAD script. One of the best kept secrets with AutoCAD. Basically it is a list of commands typed into a text file in the same order you would type them on the command line. Save the file with a .scr extension and it can be run from within AutoCAD. Quote Link to comment Share on other sites More sharing options...
dbgeek Posted December 23, 2008 Share Posted December 23, 2008 Ok I have never heard of that. Could be useful in the future I will look into it. Quote Link to comment Share on other sites More sharing options...
matma7 Posted December 23, 2008 Author Share Posted December 23, 2008 i'll bear that in mind regarding the scripts. Maybe that will be my next area for research as creating Lisps is way beyond my ability at the moment. Kind Regards Matt Quote Link to comment Share on other sites More sharing options...
dbroada Posted December 23, 2008 Share Posted December 23, 2008 like I said, one of the best kept secrets if it can be done from the command line scripts are brilliant. There is no error trapping so you do need care but if you find that you often repeat tasks they are a big time saver. A script of mine here, although unusual in that it calls a VBA module. sdi 1 new acadiso vbastmt DxfImport("C:\08_0.dxf") saveas 2000 "C:\08" new acadiso vbastmt DxfImport("C:\09_0.dxf") saveas 2000 "C:\09" new acadiso vbastmt DxfImport("C:\11_0.dxf") saveas 2000 "C:\11" resume 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.