View
159
Download
1
Embed Size (px)
DESCRIPTION
Robert is head of the Robert Green Consulting Group, and an 18 year veteran speaker at Autodesk University. You have likely read his work in Cadalyst magazine, where he authors the CAD Manager; column, or in his bi-monthly CAD Manager's Newsletter. He holds a degree in mechanical engineering from the Georgia Institute of Technology, and gained his CAD skills from 28 years of AutoCAD®, MicroStation®, and various MCAD software systems. Since starting his own company in 1991, Robert has performed consulting and teaching duties for private clients throughout the United States, Canada and Europe.
Citation preview
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Customizing
Crash Course
Robert Green www.CAD-Manager.com
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
The Fundamentals
AutoLISP
For task automation
CUI
For desktop customization
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
The CUI command …
• Where everything
is located
• What the
components do
• What the four
areas of the CUI
command allow
you to do
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Workspaces …
• What the user
sees/works with
• How they judge
your CUI files
• The flexible UI part
of the CUI
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
AutoLISP
• ..
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Custom Workspaces …
• Let’s try it out!
• Backup your CUI
before you start
• Build the Workspace
by toggling on/off the
various components.
• Have fun!
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Key files and why they matter
• LSP
• Load in order
• What to mess with
• What not to!
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
All those wacky file names …
• ACAD20XX.LSP (XX is version)
• ACAD.LSP
• ACAD20XXDOC.LSP (XX is version)
• ACADDOC.LSP
• MENUNAME.MNL
• Help …
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
What do they do …
• 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 …
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
ACADDOC.LSP approach …
• Use ACADDOC.LSP to get started
• You create your own ACADDOC.LSP so you
can’t really mess it up
• It loads with every new drawing
• Put in in the SUPPORT folder and start hacking
away
• If you mess up too bad, just delete!
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Syntax Basics
• Lists and Arguments
• Rules of AutoLISP
• Variables
• Functions
• Accessing the
command line
• Special characters
• User input
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Lists and Arguments
• (+ 20 30)
o Here the + is a FUNCTION and the two numbers
are ARGUMENTS
• (command “line” “0,0” “1,1” “”)
o Here COMMAND is the function, all others are
ARGUMENTS
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
The Command Line
• How would you work normally?
• Draw a line between two user points
o Type in LINE to start the line command
o Click POINT for first point location
o Click POINT for second point location
o Type in ENTER to halt the command
• In AutoLISP: (command “line” pause pause “”)
• PAUSE instruction waits for the user
• The “” is equal to hitting the ENTER key …
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Some Rules
“For every ( there is an equal and opposite )” – Newton
Like this: (setq A 3.0)
Not like this: (setq A 3.0)) or (setq A 3.0
Same goes for quote marks!
Like this: (setq name “Robert Green”)
Not like this: (setq name “Robert Green)
(setq name Robert Green”)
When formatting numbers always avoid “invalid dotted pairs”
Like this: (setq A 0.5)
Not like this: (setq A .5)
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
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 …
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
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.
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
User Function Examples
(defun C:ZA ()
(command “.zoom” “a”)
(princ)
)
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
User Function Examples
(defun C:VR ()
(command “viewres” “y” “5000”)
)
(defun C:BL ()
(command “-color” “BYLAYER”)
(command “-linetype” “set” “BYLAYER” “”)
(princ)
)
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Fillet Zero Function
Fillet Zero
(defun c:fz ()
(setvar “filletrad” 0.0)
(command “.fillet” pause pause)
(princ)
)
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Improved Fillet Zero
(defun c:fz ()
(setq old_filletrad (getvar “filletrad”))
(setvar “filletrad” 0.0)
(command “.fillet” pause pause)
(setvar “filletrad” old_filletrad)
(princ)
)
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Auto Purge Function
Auto Purge
(defun c:atp ()
(command “-purge” “a” “*” “n” “.qsave”)
(princ)
)
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
More Bits and Bytes …
• Undefine
• Dot form
• Redefine
• Alerts
• CMDECHO
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
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.
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
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 ...
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
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.
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Undefining revisted …
• What if your users find out about REDEFINE and start
REDEFINING your UNDEFINES?
• Just undefine the redefine like this:
• (command “.undefine” “REDEFINE”)
• That’ll show ‘em …
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
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!
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Alerting the user …
• You can send a message to the user like this:
(alert “Message goes here”)
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
What Does This Do?
(command “.undefine” “QSAVE”)
(defun c:qsave ()
(command “-purge” “b” “*” “n”)
(command “.qsave”)
(princ)
)
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
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)
)
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
The CUI command revisited …
• Create some
commands
• Add some toolbars
• Preview the results
• Workspaces react
accordingly!
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Macro cheat sheet
• Using your AutoCAD knowledge to write
some cool functionality into your CUI files
• What does this macro do?
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
The transfer tab …
• Transferring elements
between CUI files
• Like a “Vulcan mind
meld” for CUI’s
FROM THE TRAILHEAD TO YOUR CAREER SUMMT.
Customizing
Crash Course
Robert Green www.CAD-Manager.com
Course files: