JasonChen Posted April 24, 2015 Posted April 24, 2015 (edited) I have learnt Autolisp on my own for several weeks but I am confused with some basics. I just came up with this weird and clearly redundant piece of code, and when I load it and type "cane" in the console, it shows "nil". When I type "cane" in AutoCAD command prompt, it asks for my radius and then stop. What is the reason for this? Btw is this a correct way of calling a function in the c: command? (defun c:cane () (setq radius (getreal "\nEnter radius: ")) (setq jas (circarea radius)) (princ jas) ) (defun circarea (rad) (setq n (* pi rad rad)) ) Edited April 26, 2015 by SLW210 Code Tags!!!! Quote
SLW210 Posted April 24, 2015 Posted April 24, 2015 Please read the Code Posting Guidelines and edit your post to include the Code in Code Tags. Quote
Cad64 Posted April 24, 2015 Posted April 24, 2015 I've moved your question to the Autolisp section: http://www.cadtutor.net/forum/forumdisplay.php?21-AutoLISP-Visual-LISP-amp-DCL Quote
Tharwat Posted April 24, 2015 Posted April 24, 2015 Nothing is wrong with that result . You can not run the routine from a console since that it is built as a standalone program that it starts with "c:" so that's why it did return nil. But if it is started without "c:" it would run as if it is running in the command line as standalone program . To explain the fore-said with modification on the codes , just remove the c: and load the function again and call it from console to see the difference like this (cane) . Hope this helps . Quote
Lee Mac Posted April 25, 2015 Posted April 25, 2015 I just came up with this weird and clearly redundant piece of code, and when I load it and type "cane" in the console, it shows "nil". When I type "cane" in AutoCAD command prompt, it asks for my radius and then stop. What is the reason for this? The function is defined with the symbol c:cane, therefore the symbol cane will hold no value when evaluated through the console unless you have assigned a value to this symbol elsewhere. On evaluating the symbol c:cane at the console, you will see a pointer to the memory address of the function definition: _$ c:cane #<USUBR @000000002e6fb930 C:CANE> You can then evaluate this function at the console as you might any other AutoLISP function: _$ (c:cane) 4.523894.52389 (The result is duplicated because princ will print the value to the command-line and will then return the supplied value, which is in turn returned by the calling function c:cane since it is the last evaluated expression - you can suppress this duplication by including a (princ) or (prin1) as the last evaluated expression, which will cause a null symbol to be returned). Prefixing the function symbol with c: has no effect when evaluating the function through AutoLISP, however, this prefix enables the function to be evaluated as a command at the AutoCAD command-line. Quote
BIGAL Posted April 26, 2015 Posted April 26, 2015 You will often see in examples here different ways of defining defuns like (AH:dothis) its the author leaving his/her signature on the code and as Lee said previously type dothis will not work, you have to use the full version (AH:dothis) 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.