Closed liesauer closed 1 month ago
Did you finalize the import?
i have some separate dxfs, what i do are just:
# 4. 合并算料单,添加分页线,并保存到指定目录
bigDxf: Drawing = None
prevPageMinY: float = None
pageLineMargin = 200
for idx, pagePath in enumerate(pagePaths):
pageNum = idx + 1
if bigDxf is None:
# 加载第一页的dxf
bigDxf = ezdxf.readfile(pagePath)
msp = bigDxf.modelspace()
# NOTE: 不能计算TEXT、MTEXT,库算不准的
bEdge = bbox.extents(msp.query("LINE LWPOLYLINE ARC CIRCLE"))
if prevPageMinY is None:
prevPageMinY = bEdge.extmin.y
if pageNum == 1:
continue
# 拼接分页线
msp.add_line([bEdge.extmin.x, prevPageMinY - pageLineMargin], [bEdge.extmax.x, prevPageMinY - pageLineMargin], {
"layer": "分页线",
})
prevPageMinY -= pageLineMargin * 2
# 拼接内容
pageDxf = ezdxf.readfile(pagePath)
pageMsp = pageDxf.modelspace()
pEdge = bbox.extents(pageMsp.query("LINE LWPOLYLINE ARC CIRCLE"))
dy = prevPageMinY - pEdge.extmax.y
importer = Importer(pageDxf, bigDxf)
for entity in pageMsp.query():
if not isinstance(entity, DXFGraphic):
continue
entity.translate(0, dy, 0)
importer.import_entity(entity)
importer.finalize()
prevPageMinY = pEdge.extmin.y + dy
Did you finalize the import?
yes
Do not modify the content during import, especially complex entities like DIMENSION. This library is not as robust as a CAD application.
BTW: This is the old way to import data, you should use the new and more reliable xref
module for that: https://ezdxf.mozman.at/docs/xref.html#importing-data-and-resources
BTW: This is the old way to import data, you should use the new and more reliable
xref
module for that: https://ezdxf.mozman.at/docs/xref.html#importing-data-and-resources
emmm, it says 'NoneType' object has no attribute 'destroy'
a = ezdxf.readfile('suanliao.1.dxf')
b = ezdxf.readfile('suanliao.2.dxf')
xref.load_modelspace(a, b)
i use xref.load_modelspace(a, b, conflict_policy=ConflictPolicy.NUM_PREFIX)
, and it works now.
when i try to import entities from one dxf to another dxf using Importer, weird error comes out, "Required anonymous geometry block for DIMENSION not defined."
when i try to step inside the source code, and i found that the
geometry
attribute exists but return the default value which isNone