Search code examples
pythonpython-3.xautocaddxfezdxf

An error occurs when using ezdxf to describe the layer property description


An error occurs when using ezdxf to describe the layer property description. There are layer names that cause errors and layer names that do not. I do not know the cause.

I tried using the code below.

lay = dwg.layers.get('MyLayerHere')
app = 'AcAecLayerStandard'
dsc = 'MyDescriptionHere'

if lay.tags.has_xdata(app):
    lay.tags.set_xdata(app, [(1000, ''), (1000, dsc)])
else:
    dwg.appids.new(app)
    lay.tags.new_xdata(app, [(1000, ''), (1000, dsc)])

error contents

Traceback (most recent call last): File "file.py", line 777, in dwg.appids.new(app) File "C:\・・・\table.py", line 63, in new raise DXFTableEntryError('%s %s already exists!' % (self._dxfname, name)) ezdxf.lldxf.const.DXFTableEntryError: APPID AcAecLayerStandard already exists!

Solution

  • This error will arise in your code when attempting to assign a description to a layer without an existing description, but within a drawing containing other layers with a description (i.e. within a drawing in which the AcAecLayerStandard Application ID is already registered).

    To avoid this, simply test whether the AcAecLayerStandard Application ID is already registered before adding it to the APPID symbol table, e.g.:

    lay = dwg.layers.get('MyLayerHere')
    app = 'AcAecLayerStandard'
    dsc = 'MyDescriptionHere'
    
    if lay.tags.has_xdata(app):
        lay.tags.set_xdata(app, [(1000, ''), (1000, dsc)])
    else:
        if app not in dwg.appids:
            dwg.appids.new(app)
        lay.tags.new_xdata(app, [(1000, ''), (1000, dsc)])