mozman / ezdxf

Python interface to DXF
https://ezdxf.mozman.at
MIT License
937 stars 191 forks source link

Required anonymous geometry block for DIMENSION not defined. #1156

Closed liesauer closed 1 month ago

liesauer commented 3 months ago

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 is None

image

image

mozman commented 3 months ago

Did you finalize the import?

liesauer commented 3 months ago

i have some separate dxfs, what i do are just:

  1. load the first page dxf contents as the big one dxf
  2. import the rest of dxfs into the big one dxf
# 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

dxfs.zip

liesauer commented 3 months ago

Did you finalize the import?

yes

mozman commented 3 months ago

Do not modify the content during import, especially complex entities like DIMENSION. This library is not as robust as a CAD application.

mozman commented 3 months ago

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

liesauer commented 1 month ago

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)

dxfs.zip

liesauer commented 1 month ago

i use xref.load_modelspace(a, b, conflict_policy=ConflictPolicy.NUM_PREFIX), and it works now.