ABC's of Autolisp by Geor
hiits my first day in"ABC's of Autolisp by George Omura" class. i tried to use this code but its not working. im sure its data type mismatch.
i simply want to program to draw a line from pt1 to pt2
(defun C:test() (setq pt1 (list (getpoint))) (setq pt2 (list (getpoint))) (command "Line" pt1 pt2) );end defun
Thanks why i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function? (defun C:test() (setq pt1 (getpoint)) (setq pt2 (getpoint)) (command "Line" pt1 pt2 ""));end defun thanks GP
hy i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function? You could just incorporate the pause function:
(defun c:TEST () (command "._line" pause pause "") (princ))
... But this may cause undesired behavior following a right click being entered in lieu of a point specification. This adaptation is a bit less prone to this undesired behavior:
(defun c:TEST () (command "._line") (princ))
... If the requirement is to use two variables, then consider using local in lieu of global variables, and avoid potential errors in the Command call by using an If statement:
(defun c:TEST (/ point1 point2) (if (and (setq point1 (getpoint "\nSpecify start point: ")) (not (initget 32)) (setq point2 (getpoint point1 "\nSpecify end point: ")) ) (command "._line" point1 point2 "") (prompt "\n** Invalid point ** ") ) (princ))
Here is an example to consider:
(defun c:getpt ( / pt ) (if (setq pt (getpoint "\nPick a point, any point: ")) (princ (strcat "\nX = " (rtos (car pt)) "\nY = " (rtos (cadr pt)) "\nZ = " (rtos (caddr pt)) ) ) ) (princ)) i saw some using command "LINE","._LINE" what is the difference? when you say "IF" and "AND" ,logically is like making nested IF expressions. right?
See here:
http://www.cadforum.cz/cadforum_en/qaID.asp?tip=2425
In your original code in the OP, were you to right click instead of select the second point (for example), you would experience undesired behavior.
In this circumstance, the If statement is testing for the two valid points needed to supply the following Command call the arguments need to complete the command successfully.
The And statement simply allows for more than one non-Nil returned value to be required, in this case being point1, and point2 local variables, in order for the If statement's test expression to pass. In addition to BlackBox's explanation:
Correct, the following expression...
(if (and ) ) ...could alternatively be written:
(if (if (if ) ) )
Here, each nested if statement forms the then-expression for the previous if statment.
Though, where additional else-expressions are not required, I'm sure that most would agree that the use of an and statement is far more readable and concise than multiple nested if statements.
页:
[1]
2