Jump to content

Lisp reads excel to only 4 decimal places.


KerrCAD

Recommended Posts

Am writing lsp code to process lat/lng data points.  The source program writes out to xlsx.  When I read in the file (many thanks to Shadi - see link below) it rounds/truncates the lat/lng data to 4 decimal places.  I'd like to get as much precision as possible.  Can anyone help me through this?

 

Shadi's code starts with this:  (vlax-get-object "Excel.Application.16")

and reads the entire file to a list quite quickly.  But I cannot find a way around the 4 decimal limit read into AutoCAD.

 

Many Thanks!

 

Excel source data:

image.png.ee36c3c23d399a92e882d851c0d6642a.png

 

 

Lisp result (with job name deleted):

image.png.811df6c78a1bf4f68a6b61fe3cab8de5.png

 

 

 

 

image.png

Link to comment
Share on other sites

@KerrCAD How are we going to know what's going on if you haven't shared your code, or at least the part you are concerned with? The original Shadi.lsp READS from excel and writes text. If yours is doing the opposite, you have to look at how you are retrieving and formatting the data and putting it back into Excel.

 

Without seeing any code, I would say the solution is - after you get your Long and Lat value real numbers, convert them to a string using (rtos VAL 2 8), where "8" is the number of decimal precision you want. Then send them to Excel.

Link to comment
Share on other sites

I couldn't find the link just then, but if he is lurking behind the scenes tonight, I am sure Lee Mac posted once about long or floating point decimal places - you might be in luck and he remembers what he wrote. Might not be in luck.

 

 

Link to comment
Share on other sites

6 hours ago, pkenewell said:

@KerrCAD How are we going to know what's going on if you haven't shared your code, or at least the part you are concerned with? The original Shadi.lsp READS from excel and writes text. If yours is doing the opposite, you have to look at how you are retrieving and formatting the data and putting it back into Excel.

 

Without seeing any code, I would say the solution is - after you get your Long and Lat value real numbers, convert them to a string using (rtos VAL 2 8), where "8" is the number of decimal precision you want. Then send them to Excel.

Fair enough.  Attached is the slightly modified version of Shadi's code.  It serves as a function that returns a list of lists.  "ReadExcel" on the command line to execute.  Also attached is a small excel file for testing.

 

DGK_Shadi.lsp DGK_Shadi.xlsx

Link to comment
Share on other sites

Also, I did not explain that the application that writes the xlsx file to be read by AutoCAD is not AutoCAD.  It is GPS software from another party. It writes out 13(?) decimals to the xlsx file, but I cannot get AutoCAD to read in more than 4 decimal places. 

 

Now I am wondering.  I only looked at the number of decimal places in the AutoCAD vlisp editor and on the command line.

 

Turns out I'm an idiot.  If I do (RTOS Lat 2 13) of the latitude read in by AutoCAD, all the decimal digits are there.  AutoCAD only returns the 1st four to the display.  Having started lisp at v10 286, I'm pretty embarrassed to admit how many years I've know this.

 

My sincere apologies for wasting your collective time.

Edited by KerrCAD
  • Like 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...