PDA

View Full Version : Divide the value stored in system variable Distance


blaine.67000
2006-06-22, 02:49 PM
I am writing a LISP code to give me the distance in decimal feet. Here is what I have so far:


;gives distance in decimal feet

(defun C:FE ()
(command "-units" "2" "3" "1" "3" "0.000" "n")
(command "DIST" pause pause)
(setq convert 12)
(/ DISTANCE convert)
(princ)
)

The problem is in the division of the distance variable. When the distance command is used, it stores a read-only variable called "DISTANCE". All I want to do is divde this variable by 12 to give me feet. I am setting up a "convert" variable because I thought that AutoLISP wouldn't let me divde the variable DISTANCE by the number twelve directly, as in:

(/ DISTANCE 12)

I would appreciate any responses to this problem.

Blaine

CAB2k
2006-06-22, 03:28 PM
Try this:
(defun c:test (/ dec decft)
(setq des (getdist "\nEnter or pick your distance."))
(setq decft (/ des 12.0))
(print decft)
(princ)
)

blaine.67000
2006-06-22, 03:45 PM
That worked. Thanks! However, I would like to know why what I had did not work. If I am going to learn AutoLISP, I need to be able to understand why what I had did not work.

Also, I believe that I am correct in my understanding that the portion of code after the defun is defining the local variables, but I don't understand why that is important or needed.

Thanks,

Blaine

Opie
2006-06-22, 03:49 PM
That worked. Thanks! However, I would like to know why what I had did not work. If I am going to learn AutoLISP, I need to be able to understand why what I had did not work.

Also, I believe that I am correct in my understanding that the portion of code after the defun is defining the local variables, but I don't understand why that is important or needed.

Thanks,

Blaine
Are you referring to the DISTANCE system variable? You would need to get the value of the variable first before placing it within a function.

(/ (getvar "DISTANCE") 12)

blaine.67000
2006-06-22, 05:46 PM
Are you referring to the DISTANCE system variable? You would need to get the value of the variable first before placing it within a function.



Yes, I am. And putting in the getvar function to retreive the DISTANCE system variable makes sense......I think.

Opie
2006-06-22, 06:39 PM
Yes, I am. And putting in the getvar function to retreive the DISTANCE system variable makes sense......I think.
You would need to do this with any system variables.

blaine.67000
2006-06-22, 06:44 PM
Also, I believe that I am correct in my understanding that the portion of code after the defun is defining the local variables, but I don't understand why that is important or needed.


Opie,

Can you comment on my above question regarding local variables.

Thanks,

Blaine

Opie
2006-06-22, 07:07 PM
Opie,

Can you comment on my above question regarding local variables.

Thanks,

Blaine
See this post. I know it doesn't relate to this actual routine, but it does explain the local variables a little.