Search code examples
pythonautocadpolylinedxf

How can I add a "dynamic" AREA attribute to a polyline using ezdxf?


I am using the ezdxf library to generate DXF files with polylines and different attributes which are given within a polyline as text. Using ezdxf, how can I create an AREA attribute which would be connected to a polyline? This means, if I open a created DXF file in AutoCAD and change the polyline geometry, then the AREA text would update its value automatically.

Here is how I do it in AutoCAD:

Assigning AREA to POLYLINE OBJECT in AutoCAD

Here is an example of what kind of behavior I want to achieve in AutoCAD:

  1. AREA attribute state when I open the DXF file:

    AREA attribute state when I open the DXF file.

  2. Changing the geometry of the POLYLINE:

    Changing the geometry of the POLYLINE

  3. After I apply the REGEN command, the AREA attribute value gets updated:

    After I apply REGEN command, the AREA attribute value gets updated.


Solution

  • It is theoretically possible, but you would need to write the definition of the Extension Dictionary attached to the attribute definition, the ACAD_FIELD dictionary contained within the Extension Dictionary, the TEXT dictionary contained within that, the FIELD entity container, and finally, the FIELD entity which references the object property itself.

    You can inspect the DXF data for each of these dictionaries & entities using a utility such as my Entity List program, and drill-down through the entries starting with the Extension Dictionary.