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: [email protected]
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
[email protected]
Network Your AutoCAD with AutoLISP
Robert Green