chiimayred Posted July 17, 2013 Posted July 17, 2013 (edited) Hi guys, Total newb here, did some reading in the tutorials area in how to write lisps and I'm having issues with it not working. I'm trying to start off really simple hence the rotate, move and scale. This is my first time trying to program so please bear with me. Here is the code: (defun C:firstprog () (command "ro" all 1,2 45) (command "m" all 0,0 50,50) (command "sc" 0,0 25.4) ) When I try to run this i get an error: nil Any help would be appreciated. Edited July 17, 2013 by chiimayred Newb to forum, added code posting Quote
SLW210 Posted July 17, 2013 Posted July 17, 2013 Start with reading Code posting guidelines and place your Code in Code Tags. Quote
Lee Mac Posted July 17, 2013 Posted July 17, 2013 Welcome to CADTutor Here are some comments to get you started: (defun c:firstprog ( ) (command "_.rotate" [color=green] ;; Always use full command name ;; "_" = use english version of command ;; "." = use non-redefined version of command[/color] "_all" [color=green];; Use underscore to use english version of keywords[/color] "" [color=green];; Equivalent to user pressing Enter[/color] "_non" [color=green];; None Object Snap modifier - ignore object snap[/color] '(1 2) [color=green];; Quoted literal list[/color] 45.0 "_move" "_all" "" "_non" '(0 0) "_non" '(50 50) "_.scale" "_all" "" "_non" '(0 0) 25.4 ) (princ)[color=green] ;; Suppress the return of the command expression (would return nil otherwise)[/color] ) One reason that your original code is causing an error is because the 'all' string is not enclosed with string delimiters (quotation marks, e.g. "all") and hence is being interpreted as a variable to be evaluated. However, since the 'all' symbol has no value in your program (i.e. it has not been defined using setq / set), it will evaluate to nil, causing the error. Quote
chiimayred Posted July 17, 2013 Author Posted July 17, 2013 Welcome to CADTutor Here are some comments to get you started: (defun c:firstprog ( ) (command "_.rotate" [color=green] ;; Always use full command name ;; "_" = use english version of command ;; "." = use non-redefined version of command[/color] "_all" [color=green];; Use underscore to use english version of keywords[/color] "" [color=green];; Equivalent to user pressing Enter[/color] "_non" [color=green];; None Object Snap modifier - ignore object snap[/color] '(1 2) [color=green];; Quoted literal list[/color] 45.0 "_move" "_all" "" "_non" '(0 0) "_non" '(50 50) "_.scale" "_all" "" "_non" '(0 0) 25.4 ) (princ)[color=green] ;; Suppress the return of the command expression (would return nil otherwise)[/color] ) One reason that your original code is causing an error is because the 'all' string is not enclosed with string delimiters (quotation marks, e.g. "all") and hence is being interpreted as a variable to be evaluated. However, since the 'all' symbol has no value in your program (i.e. it has not been defined using setq / set), it will evaluate to nil, causing the error. Thanks Lee Mac! Would there be any chance you could explain your philosophy for doing it that way? It would be greatly appreciated. Quote
Lee Mac Posted July 17, 2013 Posted July 17, 2013 Would there be any chance you could explain your philosophy for doing it that way? Is there a specific part of the code that you do not understand? Have you read my comments? Quote
chiimayred Posted July 17, 2013 Author Posted July 17, 2013 (edited) I have, it's mostly why I would want to use the "_non", everything else i can understand why. Also, here is an updated version of the code and I'm getting an error: nil still... can't figure it out, can you please help me troubleshoot it (defun C:firstprog ( ) (command "_.rotate" "_all" "" "_non" '(1 2) 45 "_move" "_all" "" "_non" '(0 0) "_non" '(50 50) "_.scale" "_all" "" '(0 0) 25.4 ) (princ) ) Edit: Figured it out... didn't add the "" after the selection from scaling, which caused the error. Thanks for your help! Edited July 17, 2013 by chiimayred missing words Quote
CheSyn Posted July 18, 2013 Posted July 18, 2013 I have, it's mostly why I would want to use the "_non", everything else i can understand why. "_non" is used to ignore OSnaps, it sets a temporary value of "None" Quote
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.