samifox Posted March 8, 2013 Share Posted March 8, 2013 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 Quote Link to comment Share on other sites More sharing options...
samifox Posted March 8, 2013 Author Share Posted March 8, 2013 why i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function? Quote Link to comment Share on other sites More sharing options...
GP_ Posted March 8, 2013 Share Posted March 8, 2013 (defun C:test() (setq pt1 (getpoint)) (setq pt2 (getpoint)) (command "Line" pt1 pt2 "") );end defun Quote Link to comment Share on other sites More sharing options...
samifox Posted March 8, 2013 Author Share Posted March 8, 2013 thanks GP hy i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 8, 2013 Share Posted March 8, 2013 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) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 8, 2013 Share Posted March 8, 2013 [w]hy i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function? 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) ) Quote Link to comment Share on other sites More sharing options...
samifox Posted March 8, 2013 Author Share Posted March 8, 2013 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? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 8, 2013 Share Posted March 8, 2013 i saw some using command "LINE","._LINE" what is the difference? See here: http://www.cadforum.cz/cadforum_en/qaID.asp?tip=2425 Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 8, 2013 Share Posted March 8, 2013 ... when you say "IF" and "AND" ,logically is like making nested IF expressions. right? 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 8, 2013 Share Posted March 8, 2013 In addition to BlackBox's explanation: When you say "IF" and "AND", logically is like making nested IF expressions. right? Correct, the following expression... ([color=blue]if[/color] ([color=blue]and[/color] [color=green] <test-expression-1> <test-expression-2> <test-expression-3>[/color] ) [color=red] <then-expression-1>[/color] [color=purple] <else-expression-1>[/color] ) ...could alternatively be written: ([color=blue]if[/color] [color=green]<test-expression-1>[/color] ([color=blue]if[/color] [color=green]<test-expression-2>[/color] ([color=blue]if[/color] [color=green]<test-expression-3>[/color] [color=green][color=red] <then-expression-1>[/color] [color=purple] <else-expression-1>[/color][/color] ) [color=green] [color=purple] <else-expression-2>[/color][/color] ) [color=green] [color=purple] <else-expression-3>[/color][/color] ) 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. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 8, 2013 Share Posted March 8, 2013 The same could be expressed as: [b][color=BLACK]([/color][/b]cond [b][color=FUCHSIA]([/color][/b][b][color=NAVY]([/color][/b]and <test-expression-1> <test-expression-2> <test-expression-3>[b][color=NAVY])[/color][/b] <else-expression-3>[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b][b][color=NAVY]([/color][/b]and <test-expression-1> <test-expression-2>[b][color=NAVY])[/color][/b] <else-expression-2> [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]<test-expression-1> <else-expression-1>[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Quote Link to comment Share on other sites More sharing options...
neophoible Posted March 8, 2013 Share Posted March 8, 2013 why i cant use the CAR and CADR functions to retrieve list component obtained with getpoint function? In case it was missed, the answer is that you CAN use them, but the point is already a list. You made it an embedded list, and that doesn't work as straightforwardly. Quote Link to comment Share on other sites More sharing options...
samifox Posted March 16, 2013 Author Share Posted March 16, 2013 hi for what reasom the main() is not calling to getTotalLength()? (defun c:main () (setq totLng getTotalLength) (princ) ) (defun getTotalLength ( / ptst pten d n6 n8 n1 n2 n k stpt enpt ) (princ "getting the total length of the line") (setq ptst (getpoint "\nStart point of line : ")) (setq pten (getpoint ptst "\nEnd point of line : ")) (setq ptst (trans ptst 1 0) pten (trans pten 1 0)) (setq d (distance ptst pten)) ) (defun getSegmentLength () (princ) ) Thanks Shay Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 17, 2013 Share Posted March 17, 2013 To solve your error: (defun c:main ( / totLng ) (setq totLng (getTotalLength)) (princ) ) (defun getTotalLength ( / ptst pten d ) (princ "getting the total length of the line") (setq ptst (getpoint "\nStart point of line : ")) (setq pten (getpoint ptst "\nEnd point of line : ")) (setq ptst (trans ptst 1 0) pten (trans pten 1 0) ) (setq d (distance ptst pten)) ) (defun getSegmentLength ( ) (princ) ) However, for what the code is doing, it could be simply: (defun c:main ( / totLng ) (setq totLng (getdist "\nPick Distance: ")) ) Quote Link to comment Share on other sites More sharing options...
samifox Posted March 17, 2013 Author Share Posted March 17, 2013 Thanks Lee i need the ptst and pted location so i cant use getdist() http://www.cadtutor.net/forum/showthread.php?77725-divide-a-line-equally-but-with-a-few-restrictions&highlight=samifox Quote Link to comment Share on other sites More sharing options...
samifox Posted March 21, 2013 Author Share Posted March 21, 2013 hi im learning how too access element in lists , why its so hard? i tried to write a program that assign 1-10 to a veriable and than prints all elements one by one. of course i end up with ugly error how to do it right? ;**accessing single element of a list page 17*; (defun c:abcd() (setq pt1(list 1 2 3 4 5 6 7 8 9 0)) (princ (car pt1)) (princ (cdar '(pt1))) ) Thanks Shay Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.