Network Your AutoCAD with AutoLISP
Transcription
Network Your AutoCAD with AutoLISP
Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer geek CAD user since 1985 CAD manager since 1989 LISP hacker since Release 9 CADENCE/Cadalyst author since 1998 Still trying to learn everything I can … Network Your AutoCAD with AutoLISP Robert Green Some fundamentals LISP – LISt Processor Should you still use LISP? Everything is in lists Network Your AutoCAD with AutoLISP Robert Green Key files and why they matter … LSP Load in order What to mess with What not to! Network Your AutoCAD with AutoLISP Robert Green All those wacky file names … ACAD20XX.LSP (system file – XX is version) ACAD.LSP (This is your file) ACAD20XXDOC.LSP (system file - XX is version) ACADDOC.LSP (This is your file) CUINAME.MNL (loads with CUI) So what does it all mean? Network Your AutoCAD with AutoLISP Robert Green What do they do, where they live … They load on startup of AutoCAD They load in a certain order (listed on previous slide) Some have code in them and some don’t (ACADDOC.LSP and ACAD.LSP don’t as an example) They reside in the SUPPORT folder … Network Your AutoCAD with AutoLISP Robert Green So what should I do … Use ACADDOC.LSP to get started You create your own ACADDOC.LSP It loads with every new drawing Put in in the SUPPORT folder and start hacking away If you mess up too bad, just delete! Network Your AutoCAD with AutoLISP Robert Green Make sure it works … Create ACADDOC.LSP Load from network? Verify operation Network Your AutoCAD with AutoLISP Robert Green Find the support folder … Use OPTIONS to find the folders … Network Your AutoCAD with AutoLISP Robert Green Add a network folder … Use OPTIONS to add it … Network Your AutoCAD with AutoLISP Robert Green Create the file … Use Notepad – not Word! Use (prompt “\nACADDOC.LSP loaded.”) as text Network Your AutoCAD with AutoLISP Robert Green Save the file … To the SUPPORT folder Use ACADDOC.LSP as the name Network Your AutoCAD with AutoLISP Robert Green Alternately … You can use APPLOAD to load files You can use STARTUP SUITE to load at each start Network Your AutoCAD with AutoLISP Robert Green Syntax Basics Lists and Arguments Rules of AutoLISP Accessing the command line Special characters Network Your AutoCAD with AutoLISP Robert Green Lists and Arguments (+ 20 30) (command “line” “0,0” “1,1” “”) Here the + is a FUNCTION and the two numbers are ARGUMENTS Here COMMAND is the function, all others are ARGUMENTS (getvar “dimscale”) Which is the function? The argument? Network Your AutoCAD with AutoLISP Robert Green What’s Going On Here? (command “viewres” “y” “5000”) (command “-color” “BYLAYER”) (command “-linetype” “set” “BYLAYER” “”) (command “menu” “menuname.mnc”) (command “viewres” “y” pause) That’s not so bad …intuitive actually … Network Your AutoCAD with AutoLISP Robert Green User functions Speed for the user Lower support for you A win-win scenario Let’s put everything we’ve learned into action to build some functions. Network Your AutoCAD with AutoLISP Robert Green User Function Examples (defun C:ZA () (command “.zoom” “a”) (princ) ) Network Your AutoCAD with AutoLISP Robert Green User Function Examples (defun C:ZA () (command “.zoom” “a”) (princ) ) Network Your AutoCAD with AutoLISP Robert Green User Function Examples (defun C:VR () (command “viewres” “y” “5000”) ) * Note that I left out PRINC? (defun C:BL () (command “-color” “BYLAYER”) (command “-linetype” “set” “BYLAYER” “”) (princ) ) Network Your AutoCAD with AutoLISP Robert Green Fillet Zero Function Fillet Zero (defun c:fz () (setvar “filletrad” 0.0) (command “.fillet” pause pause) (princ) ) * What have I not done in this function? Network Your AutoCAD with AutoLISP Robert Green Improved Fillet Zero (defun c:fz () (setq old_filletrad (getvar “filletrad”)) (setvar “filletrad” 0.0) (command “.fillet” pause pause) (setvar “filletrad” old_filletrad) (princ) ) * Note how we store and recall the FILLETRAD so the function puts things back the way they were! Network Your AutoCAD with AutoLISP Robert Green Auto Purge Function Auto Purge (defun c:atp () (command “-purge” “a” “*” “n” “.qsave”) (princ) ) (defun c:atp () (command “-purge” “b” “*” “n” “.qsave”) (princ) ) Network Your AutoCAD with AutoLISP Robert Green Take Control of the Command Set … Undefine Dot form Redefine Alerts CMDECHO Network Your AutoCAD with AutoLISP Robert Green Undefining … (command “.undefine” “LINE”) (command “.undefine” “TORUS”) Don’t want them messing with a command? Just undefine it … Now you can SUBTRACT from the AutoCAD Command set in your ACADDOC.LSP file. Network Your AutoCAD with AutoLISP Robert Green The DOT form … Invoke commands like this: .LINE Note the dot “.” character? This allows you to invoke a command whether it has been undefined or not! This is our little secret right ... Network Your AutoCAD with AutoLISP Robert Green Redefining … (command “.redefine” “LINE”) (command “.redefine” “TORUS”) Want to be sure that a command is active? Just redefine it … Now you can UNSUBTRACT from the AutoCAD Command set with ease. Network Your AutoCAD with AutoLISP Robert Green Undefining revisited … What if your users find out about REDEFINE and start REDEFINING your UNDEFINES? Just undefine the redefine like this: (command “.undefine” “REDEFINE”) That’ll stop users from redefining … Network Your AutoCAD with AutoLISP Robert Green Redefining … You can undefine a command and redefine it like this: (command “.undefine” “TORUS”) (defun C:TORUS () (alert “Don’t use that command!”) (princ) ) Now you do whatever you want! Network Your AutoCAD with AutoLISP Robert Green What Does This Do? (command “.undefine” “QSAVE”) (defun c:qsave () (command “-purge” “b” “*” “n”) (command “.qsave”) (princ) ) Network Your AutoCAD with AutoLISP Robert Green Alerting the user … You can send a message to the user like this: (alert “Message goes here”) Network Your AutoCAD with AutoLISP Robert Green Command echo (CMDECHO) Run in STEALTH mode like this: (defun C:BL () (setvar “cmdecho” 0) (command “-color” “BYLAYER”) (command “-linetype” “set” “BYLAYER” “”) (setvar “cmdecho” 1) (princ) ) * SETVAR is on or off so no need to store it’s value Network Your AutoCAD with AutoLISP Robert Green Automate the Folders … Registry reads Registry writes Impose profiles without actually using profiles Let’s make the leap Network Your AutoCAD with AutoLISP Robert Green Locate the registry keys Use REGEDIT Find the version Find the profile Network Your AutoCAD with AutoLISP Robert Green Locate the registry keys Find the key Network Your AutoCAD with AutoLISP Robert Green Override with code (setenv "PrinterConfigDir" Network Your AutoCAD with AutoLISP Robert Green "C:\\TEMP\\acad\\Plotters") Synch the Folders … Network files Copy to local folder Consistency No permissions hassles Network Your AutoCAD with AutoLISP Robert Green Add this to ACADDOC.LSP (command "shell" "robocopy \\\\server\\folder c:\\temp /e") Where \\\\server is your server location And \\folder is the full path to the files Let’s see an example: Network Your AutoCAD with AutoLISP Robert Green Compile and remote load code … VLIDE Load operations Network Your AutoCAD with AutoLISP Robert Green VLIDE environment … You can write code in the VLIDE window like this: Network Your AutoCAD with AutoLISP Robert Green Compile your code … Use the VLIDE environment like this: (vlisp-compile ‘st “c:\\test\\myprog.lsp”) You’ll get MYPROG.FAS as a result Network Your AutoCAD with AutoLISP Robert Green Load compiled code … Use a LOAD statement like this: (load “c:\\test\\myprog.fas”) Now your LSP code is secure! Be sure not to lose your LSP file though! Network Your AutoCAD with AutoLISP Robert Green Centralized code … (if (findfile "x:\\autolisp\\utils1.fas") (load "x:\\autolisp\\utils1.fas")) ) Network loaded compiled programs are the way to go for security. Load these files from your ACADDOC.LSP Network Your AutoCAD with AutoLISP Robert Green Wrapping up: Resources The course handout (it has extra coverage) CAD-Manager.com/su password = synergis Email: rgreen@CAD-Manager.com Cadalyst Magazine (Hot Tip Harry) Developer’s Help The Garden Path example Network Your AutoCAD with AutoLISP Robert Green Thank you and keep in touch! Robert Green rgreen@CAD-Manager.com Network Your AutoCAD with AutoLISP Robert Green