Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DXF: Get exported precision (decimal places) of coordinates and angles from DXF

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
Anonymous
3263 Views, 13 Replies

DXF: Get exported precision (decimal places) of coordinates and angles from DXF

Hi,

 

I am trying to determine the precision of coordinates and angles of a DXF file.

 

As AutoCAD and other CAD software offers the option to round floating point values to a number of decimal places between 0 and 16, I would like to know if there is any fail-safe method to find the number of decimal places which the exporting user has selected upon exporting the DXF file.

 

As any trailing zeros in floating point numbers are cut off I cannot be sure if the user just set all possible variables and coordinates to integers or if the number of decimal places is just set to 1 upon export and is thus lacking precision.

 

Is there any variable to read this from?

 

Many thanks in advance.

Labels (1)
  • dxf
13 REPLIES 13
Message 2 of 14
ronjonp
in reply to: Anonymous

Assuming you're writing DXF, look into the 'tostring' function by Michael Puckett.

Message 3 of 14
CodeDing
in reply to: Anonymous

@Anonymous,

 

Ron has provided an awesome function. But there are many questions perhaps that arise surrounding your specific situation.. Are you interpreting the output from a file? from a function? are you implementing this within a function for a user to use? what are the circumstances surrounding the variable(s) leading up to your function implementation?

 

Precision is Managed within AutoLISP, it is never intentionally lost, so we would need to know how the function(s) are written and where you plan to intervene along that process to give you a better idea of how to proceed.

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 4 of 14
leeminardi
in reply to: Anonymous

The database precision for real number is approximately 15 significant digits.  The units command controls how many decimal places of a coordinate are shown.  The displayed number is rounded to the number of decimal places specified by the units command.  AutoCAD calculations are based on the stored number not the rounded displayed number.

 

The following is a clip from the DXF file.  The precision you see in this file is not affected by the units command.  Note that the line coordinates show 16 significant digits and the arc start and end angle values (dxf codes 50 and 51)  do as well.

 

If you are getting some surprised rounding be careful you are not doing mixed mode math.

image.png

lee.minardi
Message 5 of 14
Anonymous
in reply to: CodeDing

@CodeDing  @leeminardi 

Thanks for your answer. But I think we have a misunderstanding. My problem is not about writing a DXF but about reading one.

My software will work independent of AutoCAD itself, it is a simple program (coded in C#) that will read and interpret the DXF as a text file.

 

I want to read a DXF file (I don't have access to the actual DWG) and calculate lengths of contour lines from the given coordinates. For this to be exact (enough) I have to make sure that the data given in the DXF is precise enough.

If, for example, I am reading a DXF with values like 1, 23, and 345 I cannot be sure if the user who has made the construction has set every coordinate to that exact value or if there is a lack of precision because the user who has saved the DXF selected the number of decimal places to be 0 and the actual values should be 1.23456, 23.45678, 345.67891 and I will thus have results with relatively big errors compared to the reality of the dwg.

 

Another example: I read a value of "0.1" from a DXF. Since trailing zeros after the decimal point are cut off in the DXF I can't be sure if the value should be exactly 0.100000 or if the user who has exported the DXF has selected the number of decimal places to be 1 and the actual value should be 0.19876543 (which will give me a relative error of nearly 50 %).

 

To solve this problem I want to have a way to get the number of decimal places which was selected by the user who has exported the DXF.

 

dxf_decimal_places.PNG

Message 6 of 14
leeminardi
in reply to: Anonymous

Coordinates, angles, and other real numbers (as opposed to integers) are not stored with a specific number of decimal places.  They are stored with a mantissa and exponent. The mantissa is limited to 56 bits and the exponent to 8 bits.  This yields approximately 16 significant digits of precision.   The user's setting for units has nothing to do with the number of decimal places for stored real numbers. In the sample DXF code in my post #4 the value 0.1 (after the 20) is the y coordinate.  The trailing zeros have been removed for ease of reading and you can assume the value is precise to 16 significant figures. 

lee.minardi
Message 7 of 14
cadffm
in reply to: leeminardi

@leeminardi 

We are talking about the DXF precision, nobody talks about units.

 

@Anonymous 

The only thing you can do is: Checking for coordinates with the most decimal places.

If it is 13 decimal places, you can be sure the setting was 13, OR HIGHER

That's all.

 

(PS: Higher setting is not the same as higher precision.

For example number 97.3873

saved with 14 decimal places = 97.3873

saved with 15 decimal places = 97.387299999999996

saved with 16 decimal places = 97.3872999999999962

What do you mean es more precision? For me it is the first one(saved with only 4 - 14 decimal places)

But right, Autocad will handle 97.3872999999999962 as 97.3873 again by import/open.

Sebastian

EESignature

Message 8 of 14
Anonymous
in reply to: leeminardi

Sorry, this is wrong regarding DXF files.

 

You are correct regarding DWG files and the way numbers are stored in the database. But when you save a drawing as DXF you can select the number of decimal places between 0 and 16.

dxf_decimal_places.PNG

See here for a comparison of 0 decimal places (left) vs. 16 (right).

dxf_decimal_places_0vs16_01.PNG

dxf_decimal_places_0vs16_02.PNG

As you can see in the screenshots every X/Y-coordinate and the bulge of a ARC vertex of LWPOLYLINE are cut off. But strangely the values of radii of CIRCLE and ARC are not cut off.

 

You can even try and reopen a DXF in AutoCAD after saving it with 0 decimal places. The coordinates are then set to the values from the DXF. The original value is lost!

This is a screenshot of a new drawing where I copied a LwPolyline from the original DXF with 16 decimal places (upper figure) and the "same" polyline from the "same" DXF with 0 decimal places (lower figure).

dxf_decimal_places_0vs16_03.PNG

Message 9 of 14
cadffm
in reply to: cadffm

@Anonymous 

Aber mal nebenbei:

 

Zumindest was AutoDESK-Produkte und andere CAD-Programme angeht welche DWG als natives Format nutzen:

Diese Einstellungsmöglichkeit kennt kaum ein Anwender!

Und Benutzer welche die Option kennen. die nutzen immer 16 (habe ich noch nie anders erlebt)

Vorgabe ist 16 und wird in 99.99% der Fälle so bleiben.

 

Wenn eine DXF Datei mit weniger wie die 16 gespeichert wurden, dann zu 99.99% in einer anderen Software.

 

=========

 

At least when it comes to AutoDESK products and other CAD programs that use DWG as their native format:

Hardly any user knows this setting option!

And users who know the option. they always use 16 (I've never experienced anything else)

The default is 16 and will remain that way 99.99% of the time.


If a DXF file less than 16 was saved, it was 99.99% saved in another software.

 

 

 

Sebastian

EESignature

Message 10 of 14
Anonymous
in reply to: cadffm

Thanks a lot. I thought as much and just wanted to make sure there is no variable in the header section which I am overlooking.

 

Still there is a very curious behaviour with different entity types. See the screenshots from my post above. X/Y coordinates are cut off as well as the bulge in a LwPolyline. But the radii of circles and lines are not cut off even when I select 0 decimal places.

Message 11 of 14
cadffm
in reply to: Anonymous

>>"Still there is a very curious behaviour with different entity types.

>>"X/Y coordinates are cut off as well as the bulge in a LwPolyline. "

>>"But the radii of circles ... are not cut off even when I select 0 decimal places."

 

I think it isn't the object type itselve, but the the dxf code.

dxf 42 = not cutted/rounded

dxf 50 = cutted/roundet

 

>>"But ...   lines are not cut off even when I select 0 decimal places."

Lines?

dxf 10(20,30) 11(21,31)210(220,230) will be cutted

so i am not sure what you mean in case of "Lines"

 

Sebastian

EESignature

Message 12 of 14
Anonymous
in reply to: cadffm

Oops, "the radii of circles and lines" was supposed to be "the radii of circles and ARCs".

Sorry for the confusion.

 

Message 13 of 14
leeminardi
in reply to: Anonymous

@cadffm 

 

The reason I mentioned the units command is because it is one of the commands, along with LUPREC and AUPREC that controls the number of displayed decimal places.  It does not affect the precision of the stored data as I pointed out.

 

@Anonymous 

An AutoCAD .dwg file is limited to 16 significant figures (or less).  When the .dwg’s binary representation of coordinates are converted to DXF ASCII numbers they are represented in a floating point format.  The precision is still limited to 16 significant digits.  If a coordinate value is greater than one then you will have less the 16 decimal places of precision. Note in your post #8 you have a coordinate of “1427.647698107399”.  This floating point number has only 12 decimal places of precision although you requested 16.  This is because 4 digits are to the left of the decimal point. As coordinates get further from 0,0,0 the number of valid decimal places to the right of the decimal points decreases.

 

I was not able to get a dialog box to display with the option to control the number of decimal places for a DXF file.  I am using AutoCAD 2019 and used File, Save As then specified DXF but no dialog box appeared.

lee.minardi
Message 14 of 14
cadffm
in reply to: leeminardi

@leeminardi 

>>"It does not affect the precision of the stored data as I pointed out.""

Right. And this thread is about the precision of stored data in a file and NOT about the displayed decimal places.

 

>>"An AutoCAD .dwg file is"

We talking about DXF files, not DWG

 

>>"specified DXF but no dialog box appeared."

Command SAVE or SAVEAS OPEN, upper right corner: TOOLS, Options, DXF-Options

It is a system-setting

 

In in commandline version of save and saveas it is an available option of option DXF. too

 

2x EDIT, time to sleep, sorry

 

Sebastian

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report