broncos15 Posted May 9, 2016 Posted May 9, 2016 I have a quick question if there is any other way to store a variable to the registry besides setenv or vl-registry-write. The reason that I ask is that setenv requires a string, which means that I have to make use of the rtos function (with maximum precision of 8 ) to convert the variable value (in this case viewtwist) to a string. The problem is that on very large projects this precision can cause some issues. Quote
marko_ribar Posted May 9, 2016 Posted May 9, 2016 You can save variables to *.txt file and then load them... Just read careful header of lisp posted here : https://www.theswamp.org/index.php?topic=50628.msg557923#msg557923 HTH, M.R. Quote
broncos15 Posted May 9, 2016 Author Posted May 9, 2016 Thanks marko, that's a cool routine! The problem I have though is that it still makes use of a conversion from a number to a string. I know that I could make use of vl-bb-set, but this only works in one session as well. Quote
Lee Mac Posted May 10, 2016 Posted May 10, 2016 which means that I have to make use of the rtos function (with maximum precision of [noparse][/noparse] The precision of rtos is only limited by the maximum precision of the double-precision floating-point format (~15 decimal places): _$ (rtos pi 2 15) "3.141592653589793" FWIW, contrary to what is stated by the developer documentation, the vl-registry-write function can also write integer values to the registry (as a REG_DWORD). Quote
Stefan BMR Posted May 10, 2016 Posted May 10, 2016 Hi broncos rtos can return up to 16 decimals, if the number is less than 1.0 (if (setq p (getpoint "\nSpecify first point: ")) (setenv "my_var" (rtos (car p) 2 16)) ) For larger numbers, it can return maximum 16 digits, so you will loose some of the precision. You can compensate using this: (if (setq p (getpoint "\nSpecify first point: ")) (setenv "my_var" (strcat "(+ " (vl-princ-to-string (fix (car p))) ".0 " (rtos (- (car p) (fix (car p))) 2 16) ")" ) ) ) Then you can retrive the stored value like this: (setq my_var (eval (read (getenv "my_var")))) Quote
broncos15 Posted May 10, 2016 Author Posted May 10, 2016 Hi broncos rtos can return up to 16 decimals, if the number is less than 1.0 (if (setq p (getpoint "\nSpecify first point: ")) (setenv "my_var" (rtos (car p) 2 16)) ) For larger numbers, it can return maximum 16 digits, so you will loose some of the precision. You can compensate using this: (if (setq p (getpoint "\nSpecify first point: ")) (setenv "my_var" (strcat "(+ " (vl-princ-to-string (fix (car p))) ".0 " (rtos (- (car p) (fix (car p))) 2 16) ")" ) ) ) Then you can retrive the stored value like this: (setq my_var (eval (read (getenv "my_var")))) I'm trying to think of way to make use of a while loop that would continue to go until it had reached the actual end of the value. For example 2.1234567890123456789 would be stored as + 2.0 0.1234567890123456 0.0000000000000000789. Do you think that this is possible? Quote
broncos15 Posted May 10, 2016 Author Posted May 10, 2016 Also, Lee, thank you so much for letting me know that the vl-registry-write function can also write integer values to the registry. I am curious, how did you find this out because I am now wondering what other functions might not be properly documented. Quote
broncos15 Posted May 10, 2016 Author Posted May 10, 2016 So I have been messing around with this, and I think the solution would involve a repeat function that makes use of function similar to strlen but for numbers (does a function like this exist?). My thought is a code like: (Repeat (numberstrlen (- myvalue (fix (myvalue))))[/color] [color=black];;;rest of code that keeps adding values to the end, but I am unsure of how to do this[/color] [color=black])[/color] Quote
Stefan BMR Posted May 10, 2016 Posted May 10, 2016 I'm trying to think of way to make use of a while loop that would continue to go until it had reached the actual end of the value. For example 2.1234567890123456789 would be stored as + 2.0 0.1234567890123456 0.0000000000000000789. Do you think that this is possible? It will not help you. All the numbers are truncated to most 16 decimals: _$ (equal 2.1234567890123456789 2.1234567890123456 1e-17) T _$ Maybe you need to reconsider your code. It might be possible to avoid this rounding error with a different approach. Quote
Lee Mac Posted May 10, 2016 Posted May 10, 2016 I am curious, how did you find this out because I am now wondering what other functions might not be properly documented. I can't remember whether I had perhaps read it on one of the CAD forums, or whether I encountered it by mistake... Quote
broncos15 Posted May 11, 2016 Author Posted May 11, 2016 It will not help you. All the numbers are truncated to most 16 decimals: _$ (equal 2.1234567890123456789 2.1234567890123456 1e-17) T _$ Maybe you need to reconsider your code. It might be possible to avoid this rounding error with a different approach. So I ended up figuring out that AutoCAD stores 48 decimal places for pi (I think this has to do with a 64 bit vs 32 bit processor), so I decided to do a repeat loop that iterates over a number and adding each digit individually to the string. Thanks again for the help. And Lee, thanks again for pointing it out, sometimes it seems like the idiosyncrasies of LISP can only be encountered through experience. 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.