samifox 发表于 2022-7-6 06:48:13

ABC's of Autolisp by Geor

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
 

(defun C:test() (setq pt1 (list (getpoint))) (setq pt2 (list (getpoint))) (command "Line" pt1 pt2)    );end defun
 
Thanks

samifox 发表于 2022-7-6 06:53:55

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

GP_ 发表于 2022-7-6 06:56:49

(defun C:test() (setq pt1 (getpoint)) (setq pt2 (getpoint)) (command "Line" pt1 pt2 ""));end defun

samifox 发表于 2022-7-6 07:00:22

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

BlackBox 发表于 2022-7-6 07:04:36

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))

Lee Mac 发表于 2022-7-6 07:08:40

 
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))

samifox 发表于 2022-7-6 07:15:30

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 发表于 2022-7-6 07:16:45

 
See here:
http://www.cadforum.cz/cadforum_en/qaID.asp?tip=2425

BlackBox 发表于 2022-7-6 07:22:06

 
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.

Lee Mac 发表于 2022-7-6 07:25:29

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
查看完整版本: ABC's of Autolisp by Geor