Author Topic: how to write a list to file and read back as a list that vl-position return T  (Read 1666 times)

0 Members and 1 Guest are viewing this topic.

RAIN CODE

  • Guest
guys, How do I write a pts coords, let say a list pts (12000.0 8000.0 0.0) of x,y,z. to a string =  "(12000.0 8000.0 0.0)". including the brackets to a file. I have lots of coords to write to a file then read from file back to a list.

I tried breaking up the x and y and write to a file then read from file and its a string. I convert them back to real and turn it back to a list. The problem is here when I use the vl-position the match nth list it returns nil even the number is exactly the same. example after I read from file and make them back as a list

ListReadBackFromFile = ((12000.0 8000.0 0.0) (16000.0 12000.0 0.0) (15000.0 7000.0 0.0))

when I use a getpoint to get the same pt -  say Pt1 = (16000.0 12000.0 0.0) which is the same as the list ListReadBackFromFile  of nth = 1

(vl-position Pt1 ListReadBackFromFile). it returns nil ???

Thanks in advance



irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Could you post your code? It might be that the accuracy is lost when writing to the file - so some of the decimal points might not be saved in the file, and then when read back the point is ever so slightly off the original.

You might try using rtos's maximum of 16 digits, but even that might still not be enough. For such absolute precision I use a function to convert reals into Base64 strings. See lines 913 and 957 here: http://caddons.svn.sourceforge.net/viewvc/caddons/Libraries/Math.LSP?revision=65&view=markup
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Maybe?
Code: [Select]
(vl-some (function(lambda(x) (< (distance '(12000.0 8000.0 0.0) 0) 0.001))) 
   '((12000.0 8000.0 0.0) (16000.0 12000.0 0.0) (15000.0 7000.0 0.0)))
Gotta run ....
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
You might want to look at this thread also: http://www.theswamp.org/index.php?topic=41698.0

Since even if you use my suggestion of saving to file using near perfect accuracy, you might still find some floating point errors.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Could you post your code? It might be that the accuracy is lost when writing to the file - so some of the decimal points might not be saved in the file, and then when read back the point is ever so slightly off the original.

You might try using rtos's maximum of 16 digits, but even that might still not be enough. For such absolute precision I use a function to convert reals into Base64 strings. See lines 913 and 957 here: http://caddons.svn.sourceforge.net/viewvc/caddons/Libraries/Math.LSP?revision=65&view=markup

Great collection of functions, Thanks for sharing Irné.  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.