why i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function?


Registered forum members do not see this ad.
hi
its 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
ThanksCode:(defun C:test() (setq pt1 (list (getpoint))) (setq pt2 (list (getpoint))) (command "Line" pt1 pt2) );end defun


why i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function?
Code:(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:
... 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:Code:(defun c:TEST () (command "._line" pause pause "") (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:Code:(defun c:TEST () (command "._line") (princ) )
Code:(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) )
"Potential has a shelf life." - Margaret Atwood
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper


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?
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
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.
"Potential has a shelf life." - Margaret Atwood
Registered forum members do not see this ad.
In addition to BlackBox's explanation:
Correct, the following expression...
...could alternatively be written:Code:(if (and <test-expression-1> <test-expression-2> <test-expression-3> ) <then-expression-1> <else-expression-1> )
Here, each nested if statement forms the then-expression for the previous if statment.Code:(if <test-expression-1> (if <test-expression-2> (if <test-expression-3> <then-expression-1> <else-expression-1> ) <else-expression-2> ) <else-expression-3> )
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.
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
Bookmarks