1

I am trying to automatically get information from 2D dxf file. The dimension class has no property about tolerance like dxf.dimtm. Such property I can find is in the DXF type Dimstyle, but that is not what I want. I found such information in dxf file looks like

A01 %%C6.14{\H0.2;\S+0.0030^ -0.0000;}

0.0030 is the upper bound and -0.0000 is the lower bound. How to get that two float using ezdxf?

appreciate to any help

Alex

mozman
  • 2,001
  • 8
  • 23
蔡承佑
  • 11
  • 2

1 Answers1

2

In general the tolerance values are stored in the DIMSTYLE entity, but can be overridden for each DIMENSION entity, you can get them by the DimstyleOverride() class as shown in the following example:

import ezdxf
from ezdxf.entities import DimStyleOverride

doc = ezdxf.readfile('your.dxf')
msp = doc.modelspace()

for dimension in msp.query('DIMENSION'):
    dimstyle_override = DimStyleOverride(dimension)
    dimtol = dimstyle_override['dimtol']
    if dimtol:
        print(f'{str(dimension)} has tolerance values:')
        dimtp = dimstyle_override['dimtp']
        dimtm = dimstyle_override['dimtm']
        print(f'Upper tolerance: {dimtp}')
        print(f'Lower tolerance: {dimtm}')

This is a very advanced DXF topic with very little documentation from the DXF creator, so you are on your own to find out the meaning of all the dim... attributes. Here you can see the result of my research, but no guarantee for the correctness of the information.

mozman
  • 2,001
  • 8
  • 23
  • Thanks for the answer! The logic is that every "dimension" follows the origin dimstyle setting. If I use CAD to change the tolerance information, then the change will be saved as override. So, if i want to get the tolerance of the dimension, i need to get it from the override. Am i correct? sorry for my poor english – 蔡承佑 Mar 19 '20 at 08:31
  • Yes this is correct, and if there are no overridden attributes in the DIMENSION entity the value of the DIMSTYLE entry will be returned. – mozman Mar 19 '20 at 16:46