(defun c:nkt()
(setq p1 (getpoint "\nNokta Seç :"))
(setq r (getreal "\n Yarıçap Giriniz:"))
(setq p2 (polar p1 0 r))
(setq aln (rtos (* pi (* r r) ) 2 3))
(setq snc (strcat "Alan: " aln " m2"))
(command "circle" p1 r "")
(command "text" "j" "tl" p2 "1" "0" snc)
)
Here are a few pointers which may steer you in the right direction -
Since
r looks to be a radius, the getdist function with
p1 as the basepoint argument may be more applicable:
You can account for null user input using a simply
if statement with an
and expression to test the validity of the value returned by each prompt, e.g.:
)
;; ... continue ...
)
)
Here, the
progn function is used to evaluate multiple expressions as part of the 'then' argument, but to supply the
if function with a single expression for the 'then' argument.
Always declare local variables within the variable list of the
defun expression, i.e.:
(defun c:nkt
( / aln p1 p2 r snc
)
This ensures that the symbols are initialised to nil within the scope of the
c:nkt function, and then return to their original values outside of this scope. Without declaring variables as local to the function, the become global variables and retain their value after the function has completed evaluation (which can lead to undesirable outcomes when building lists) - for more on this, you may wish to read my tutorial
here.
When evaluating commands using the
command function in AutoLISP, it is good practice to prefix the command name with an underscore (
_) and period (
.). The underscore indicates that the command name that follows is the English command name, else it is interpreted as a localised command name in non-English versions of AutoCAD. The period ensures that the original definition of the command is executed, in case the command has been redefined in the current environment.
For example:
When supplying point arguments to a command in AutoLISP, the points will be affected by any Object Snap modes active when the command is evaluated. This can result in points snapping to nearby objects outside of the user's control.
To avoid this, either disable all Object Snap modes prior to executing the command by modifying the value of the OSMODE system variable, or precede the point input with the "_non" or "_none" Object Snap modifier, indicating that no Object Snap modes should be used for the following input.
For example:
Be careful when executing the
TEXT or
-TEXT command from AutoLISP, as the number of prompts will depend upon whether or not the active Text Style has a non-zero text height. If the text height is zero, the user will receive an additional prompt for text height.
You can account for this by checking the text height associated with the active Text Style, or alternatively, you can use
entmake or
entmakex to create the text object.
When using
rtos to format the circle area to three decimal places, be aware that leading and trailing zeroes will be controlled by the value of the
DIMZIN system variable.