0

given the code below, how can I change the dimension units into inches. code:

import ezdxf
from ezdxf import units
doc = ezdxf.new('R2010', setup=True)
doc.units = units.IN 
msp = doc.modelspace()
msp.add_line((0.0, 0.0),(0.0, 10.0))

dim = msp.add_linear_dim(
base=(5.0, 5.0),
p1=(0.0, 0.0),  
p2=(0.0, 10.0), 
dimstyle="EZDXF",
override={
"dimtfill": 1,
"dimtxt": 1,
},          
angle=90
)
doc.saveas("dim_example.dxf")
  • your `doc.units = units.IN` are already set to inches. So your document is already in inches. If you need to convert your numbers from mm to inches, just divide them by 25.4 –  Oct 21 '22 at 10:21
  • but in the dxf file that's saved, the dimension text shows 1000 while my line is 10 units, even if I divide by 25.4, it's still not correct. – mohammad Abdelkhalek Oct 21 '22 at 10:26
  • Then divide by 100? The division by 25.4 is assuming your units are mm. –  Oct 21 '22 at 10:29
  • can you tell me how to make that division in dimension? – mohammad Abdelkhalek Oct 21 '22 at 10:43
  • instead of `5.0` you write `5.0/25.4`. same for the rest of the numbers –  Oct 21 '22 at 10:46
  • I think that would change the actual dimension of the lines, I should've noted that the DIST command in autocad gives me 10 units which is correct. – mohammad Abdelkhalek Oct 21 '22 at 11:00
  • so I don't understand your question then. You want to change some units to inches. First you need to know what units you have, then multiply or divide by some factor that converts this two units. –  Oct 21 '22 at 11:01
  • the drawing file unit is set to inches, the line is 10 inches, when you measure the line in autocad, it gives the correct length, but when you create a linear dimension, it multiplies that value by 100, giving 1000. so I think there's something wrong with the dimension style, not the drawing. is that clearer? – mohammad Abdelkhalek Oct 21 '22 at 11:09
  • The predefined `EZDXF` dimension style uses `DIMLFAC = 100` which sets the length factor to 100. This is documented in the tutorial for linear dimensions: https://ezdxf.mozman.at/docs/tutorials/linear_dimension.html - you must create your own dimension style that suits your needs. – mozman Oct 28 '22 at 05:09

0 Answers0