Jump to content
chiimayred

[LISP] First time writing LISP routine... trying to rotate, move and scale

Recommended Posts

chiimayred

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 by chiimayred
Newb to forum, added code posting

Share this post


Link to post
Share on other sites
Lee Mac

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.

Share this post


Link to post
Share on other sites
chiimayred
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.

Share this post


Link to post
Share on other sites
Lee Mac
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?

Share this post


Link to post
Share on other sites
chiimayred

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 by chiimayred
missing words

Share this post


Link to post
Share on other sites
CheSyn
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"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×