Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD...

45
Network Your AutoCAD with AutoLISP Robert Green

Transcript of Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD...

Page 1: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Page 2: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Robert Green bio …

Mechanical engineer turned computer geekCAD user since 1985CAD manager since 1989LISP hacker since Release 9 CADENCE/Cadalyst author since 1998Still trying to learn everything I can …

Page 3: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Some fundamentalsLISP – LISt ProcessorShould you still use LISP?Everything is in lists

Page 4: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Key files and why they matter …

LSPLoad in orderWhat to mess withWhat not to!

Page 5: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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?

Page 6: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

What do they do, where they live … They load on startup of AutoCADThey 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 …

Page 7: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

So what should I do … Use ACADDOC.LSP to get startedYou create your own ACADDOC.LSP It loads with every new drawingPut in in the SUPPORT folder and start hacking awayIf you mess up too bad, just delete!

Page 8: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Make sure it works …

Create ACADDOC.LSPLoad from network?Verify operation

Page 9: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Find the support folder … Use OPTIONS to find the folders …

Page 10: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Add a network folder … Use OPTIONS to add it …

Page 11: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Create the file … Use Notepad – not Word!Use (prompt “\nACADDOC.LSP loaded.”) as text

Page 12: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Save the file … To the SUPPORT folderUse ACADDOC.LSP as the name

Page 13: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Alternately … You can use APPLOAD to load filesYou can use STARTUP SUITE to load at each start

Page 14: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Syntax Basics Lists and ArgumentsRules of AutoLISPAccessing the command lineSpecial characters

Page 15: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Lists and Arguments (+ 20 30)

Here the + is a FUNCTION and the two numbers are ARGUMENTS

(command “line” “0,0” “1,1” “”) Here COMMAND is the function, all others are ARGUMENTS

(getvar “dimscale”)Which is the function? The argument?

Page 16: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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 …

Page 17: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

User functions Speed for the userLower support for youA win-win scenarioLet’s put everything we’ve learned into action to build some functions.

Page 18: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

User Function Examples

(defun C:ZA ()(command “.zoom” “a”)(princ)

)

Page 19: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

User Function Examples

(defun C:ZA ()(command “.zoom” “a”)(princ)

)

Page 20: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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)

)

Page 21: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Fillet Zero FunctionFillet Zero(defun c:fz () (setvar “filletrad” 0.0)(command “.fillet” pause pause)(princ)

)

* What have I not done in this function?

Page 22: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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!

Page 23: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Auto Purge FunctionAuto Purge(defun c:atp () (command “-purge” “a” “*” “n” “.qsave”)(princ)

)

(defun c:atp () (command “-purge” “b” “*” “n” “.qsave”)(princ)

)

Page 24: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Take Control of the Command Set …

UndefineDot formRedefine AlertsCMDECHO

Page 25: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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.

Page 26: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

The DOT form … Invoke commands like this: .LINENote the dot “.” character?This allows you to invoke a command whether it has been undefined or not!This is our little secret right ...

Page 27: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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.

Page 28: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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 …

Page 29: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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!

Page 30: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

What Does This Do?(command “.undefine” “QSAVE”)

(defun c:qsave () (command “-purge” “b” “*” “n”)(command “.qsave”)(princ)

)

Page 31: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Alerting the user … You can send a message to the user like this:

(alert “Message goes here”)

Page 32: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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

Page 33: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Automate the Folders …Registry readsRegistry writesImpose profiles without actually using profilesLet’s make the leap

Page 34: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Locate the registry keys

Use REGEDITFind the versionFind the profile

Page 35: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Locate the registry keys

Find the key

Page 36: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Override with code

(setenv "PrinterConfigDir" "C:\\TEMP\\acad\\Plotters")

Page 37: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Synch the Folders …Network filesCopy to local folderConsistency No permissions hassles

Page 38: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Add this to ACADDOC.LSP

(command "shell" "robocopy \\\\server\\folder c:\\temp /e")

Where \\\\server is your server locationAnd \\folder is the full path to the files

Let’s see an example:

Page 39: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Compile and remote load code …VLIDELoad operations

Page 40: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

VLIDE environment … You can write code in the VLIDE window like this:

Page 41: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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

Page 42: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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!

Page 43: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert 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

Page 44: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Wrapping up: ResourcesThe course handout (it has extra coverage)CAD-Manager.com/su password = synergisEmail: [email protected] Magazine (Hot Tip Harry)Developer’s HelpThe Garden Path example

Page 45: Network Your AutoCAD with AutoLISP - Synergis Your AutoCAD with AutoLI… · Network Your AutoCAD with AutoLISP Robert Green Robert Green bio … Mechanical engineer turned computer

Network Your AutoCAD with AutoLISPRobert Green

Thank you and keep in touch!

Robert [email protected]