Академический Документы
Профессиональный Документы
Культура Документы
Contact
Site Map
AutoLISP
Beginners' Tutorials
Intermediate Tutorials
Advanced Tutorials
Application Tutorials
Tips'n'Tricks
Visual LISP
Beginners' Tutorials
Intermediate Tutorials
DCL
Beginners' Tutorials
Intermediate Tutorials
VBA
VBA Tutorials
VBA Applications
Tips'nTricks
AutoCAD
Customization Tutorials
Tips'n'Tricks
Reference
AutoLISP Functions
Visual LISP Sample Files
DXF Group Codes
The AutoCAD APIs
DCL Tile Attributes
AutoLISP DCL Functions
System Variables
AutoCAD Object Model
Sin and Cos Functions
VLAX Enumeration
Download
Forum
Conditionals
by Kenny Ramage
(If) is probably the most important and widely use condition statement.
Unlike other languages though, you can match only one (if) statement with a then statement. The syntax is as follows :
(if xyz
(then do this)
(else do this)
)
If you need to evaluate more than one then, or else statement, you must use the (progn) function. Here's another example :
(defun c:testprogn ()
(setq a (getreal "\nEnter a Number : ")
b (getreal "\nEnter Second Number : ")
);setq
(if (= a b)
(progn
(prompt "\nBoth Numbers are equal")
(prompt "\nHere is Another statement")
(prompt "\nAnd Another One")
);progn
(prompt "\nBoth numbers are not equal")
);if
(princ)
);defun
(princ)
You can use as many statements as you like within the (progn) function.
You can also use (if) along with logical operators. They are functions that determine how two or more items are compared.
The available logical operators are :
AND OR NOT
(defun c:testor ()
(setq a (getstring "\nAre you Male? Y/N : "))
(if
(or
(= a "y")
(= a "Y")
);or
(prompt "\nHello Sir")
(prompt "\nHello Madam")
);if
(princ)
);defun
(princ)
A Relation Operator is a function that evaluates the relationship between two or more items. Relationship Operators
available are :
Let's look a bit closer at the (eq) and the (equal) functions.
The (eq) function determines whether two expressions are bound to the same object.
(eq a c) would return nil, a and c are not the same list.
(eq c b) would return true, b and c are exactly the same list.
The (equal) function determines whether two expressions evaluate to the same thing. You can use the optional numeric
argument, fuzz, to specify the maximum amount by which both expressions can differ and still be considered equal.
(setq a '(x y z))
(setq b '(x y z))
(setq c b)
(setq m 1.123456))
(setq n 1.123457))
What about a Multiple (if) function. The (cond) function works very much like (if), except (cond) can evaluate any number
of test conditions.
Once (cond) finds the first condition that is true, it processes the statements associated with that condition. (It only processes
the first true condition). Here's an example :
(defun c:testcond ()
(setq a
(strcase (getstring "\nSize of Bolt (M10,M12,M16): ")
);strcase
);setq
(cond
((= a "M10") (prompt "\nYou have choosen M10"))
((= a "M12") (prompt "\nYou have choosen M12"))
((= a "M16") (prompt "\nYou have choosen M16"))
(T (prompt "\nUnknown Bolt Size"))
);cond
(princ)
);defun
(princ)
AutoLISP
AutoLISP Beginners' Tutorials
AutoLISP Intermediate Tutorials
AutoLISP Advanced Tutorials
AutoLISP Application Tutorials
AutoLISP Tips'n'Tricks
AfraLISP Archive
‘Hey, what's happened to AfraLISP?’ If you've visited our site before, you'll notice some big changes. We're currently
revamping the entire site to bring you updated tutorials and a better user experience. However, if there's something you can't
find, the AfraLISP Archive contains a full copy of the original site as originally created by Kenny Ramage.
Online Books
The ABC's of AutoLISP
The Visual LISP Developer's Bible
AutoLISP Forums
CADTutor
Autodesk Discussion Groups
Autodesk User Group International (AUGI)
The Swamp
Back to top
Home
Cared for by David Watson © 2018