Replies: 2 comments 3 replies
-
This is not as trivial as you may think, this post tries to clarify the question:
If this assumptions are true, you have to scale the whole DXF document (model space) by factor 25.4 (25.4 mm = 1 inch). This can be done with ezdxf to some extent, but it will mess up DIMENSION entities, paper space layouts, and possibly other structures that I am not yet thinking of. |
Beta Was this translation helpful? Give feedback.
1 reply
-
import ezdxf
from ezdxf.math import Matrix44
from ezdxf import units
doc = ezdxf.readfile("inch.dxf")
INCH_TO_MM = 25.4
m = Matrix44.scale(sx=INCH_TO_MM, sy=INCH_TO_MM, sz=INCH_TO_MM)
for entity in doc.modelspace():
try: # not all entities are transformable
entity.transform(m)
except NotImplementedError:
print(f"ignored entity {str(entity)}")
# Not important, just to store the correct information in the DXF header:
doc.header["$INSUNITS"] = units.MM
doc.header["$MEASUREMENT"] = 1 # for metric; 0 for imperial
doc.saveas("mm.dxf") |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
makew0rld
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am using a software that ignores the units specified in the DXF file, and just interprets all numbers as being millimeters. But the DXF files I have use inches as the unit. How can I convert (by multiplying) all the measurements in the file to be correct for millimeters instead? Changing the dimensions of an entity seems easy enough, but I can't see how to iterate over all the entities in a document and change them.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions