Jump to content

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


chiimayred

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...