problem
ezdxf readfile() overwrites $TDCREATE with the current time; saveas() stamps $TDUPDATE
Scrubbing a DXF with ezdxf 1.4.4: I set $TDCREATE/$TDUPDATE/$TDUCREATE/$TDUUPDATE to a fixed Julian date before doc.saveas(), then re-read the file with ezdxf.readfile() to verify. The check doc.header['$TDCREATE'] == 2459580.5 fails: the re-read document reports $TDCREATE as today's date and time (e.g. 2461329.58), and the saved file's $TDUPDATE is the wall-clock save time. $TDUCREATE/$TDUUPDATE keep my value. It looks like the header write is being ignored, but grepping the DXF shows $TDCREATE was written correctly and only $TDUPDATE changed.
doc.header['$TDCREATE'] = 2459580.5
doc.saveas('out.dxf')
print(ezdxf.readfile('out.dxf').header['$TDCREATE']) # 2461329.58..., not 2459580.51 solution
ranked by outcome — not votes
Accepted
Two separate ezdxf behaviours (1.4.4, ezdxf/document.py):
- Loading stamps
$TDCREATE.Drawing._finalize_setup()runs for new and loaded drawings and calls_setup_metadata(), which doesself.header["$TDCREATE"] = juliandate(datetime.now()). Any document returned byezdxf.readfile()/recover.readfile()therefore reports the load time, not the file's value. - Saving stamps
$TDUPDATEand the version GUID._update_metadata()(called fromwrite/saveas) sets$TDUPDATE = juliandate(now)and callsreset_version_guid(). It also writes anEZDXF_METAmarker that includes a timestamp.
Fix for deterministic output:
import ezdxf
ezdxf.options.write_fixed_meta_data_for_testing = True # before saveas()
# all four TD* dates -> juliandate(2000-01-01) == 2451545.0, constant GUIDs and markerVerify from the serialized header, not from a re-loaded Drawing:
head = open('out.dxf').read().split('ENDSEC', 1)[0].splitlines()
dates = {head[i].strip(): float(head[i + 2]) for i in range(len(head) - 2)
if head[i].strip() in {'$TDCREATE', '$TDUPDATE', '$TDUCREATE', '$TDUUPDATE'}}
assert set(dates.values()) == {2451545.0}Activity
Tags
Version context
ezdxf : 1.4.4
python : 3.12