2

I want to know how to edit AutoCAD's Layer Description property.

I have referenced the ezdxf documentation but I do not know how.

Please tell me an example of how to use it.

Lee Mac
  • 15,615
  • 6
  • 32
  • 80
leez
  • 85
  • 8

1 Answers1

2

The Layer Description in AutoCAD is stored within the Extended Entity Data (xData) of the Layer Table record, associated with the second occurrence of DXF group 1000 under the AcAecLayerStandard Application ID.

As such, you should be able to configure the layer description using ezdxf using something along the lines of the following:

import ezdxf

dwg = ezdxf.readfile('C:\YourFilename.dxf')
lay = dwg.layers.get('YourLayerHere')
app = 'AcAecLayerStandard'
dsc = 'YourDescriptionHere'

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)])

The above is entirely untested.

Lee Mac
  • 15,615
  • 6
  • 32
  • 80
  • I'm sorry. Another question. If it is already in the layer description, how can I add it to it? – leez Aug 07 '19 at 01:59
  • Retrieve the current value associated with the second DXF group 1000 entry within the xdata for the `AcAecLayerStandard` application ID, concatenate your description to the start or end of it, and then modify the xdata using the method demonstrated above. – Lee Mac Aug 07 '19 at 12:19
  • Thank you. Sorry to trouble you, but can you tell me the code? – leez Aug 08 '19 at 01:22
  • 1
    changes in upcoming ezdxf v0.10 - `tags` attribute do not exist anymore, but algorithm works as shown, just remove `tags`: `lay.new_xdata(...)`; added `description` property to layer table entry to get/set layer description (also for `transparency`) – mozman Aug 08 '19 at 04:49