Skip to content

Commit

Permalink
add BaseAttrib.discard_mtext() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed Nov 8, 2024
1 parent b14aa29 commit 05ca6ae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/source/blocks/attdef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ Inherited DXF attributes :ref:`Common graphical DXF attributes`

.. automethod:: embed_mtext

.. automethod:: discard_mtext

.. _DXF Reference: http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-F0EA099B-6F88-4BCC-BEC7-247BA64838A4
1 change: 1 addition & 0 deletions docs/source/blocks/attrib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ Inherited DXF attributes :ref:`Common graphical DXF attributes`

.. automethod:: embed_mtext

.. automethod:: discard_mtext

.. _DXF Reference: http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-7DD8B495-C3F8-48CD-A766-14F9D7D0DD9B
11 changes: 10 additions & 1 deletion src/ezdxf/entities/attrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def set_mtext(self, mtext: MText, graphic_properties=True) -> None:

def embed_mtext(self, mtext: MText, graphic_properties=True) -> None:
"""Set multi-line properties from a :class:`MText` entity and destroy the
source entity afterwards.
source entity afterward.
The multi-line ATTRIB/ATTDEF entity requires DXF R2018, otherwise an
ordinary single line ATTRIB/ATTDEF entity will be exported.
Expand All @@ -380,6 +380,15 @@ def embed_mtext(self, mtext: MText, graphic_properties=True) -> None:
self.set_mtext(mtext, graphic_properties)
mtext.destroy()

def discard_mtext(self) -> None:
"""Discard multi-line feature.
The embedded MTEXT will be removed and the ATTRIB/ATTDEF will be converted to a
single-line attribute.
"""
self._embedded_mtext = None
self.dxf.attribute_type = const.ATTRIB_TYPE_SINGLE_LINE

def register_resources(self, registry: xref.Registry) -> None:
"""Register required resources to the resource registry."""
super().register_resources(registry)
Expand Down
11 changes: 9 additions & 2 deletions tests/test_02_dxf_graphics/test_208_attrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import ezdxf
from ezdxf.entities import Attrib, MText
from ezdxf.entities.attrib import EmbeddedMText, EmbeddedMTextNS
from ezdxf.lldxf.const import DXF12, DXF2000
from ezdxf.lldxf import const
from ezdxf.lldxf.tagwriter import TagCollector, basic_tags_from_text
from ezdxf.math import Matrix44
from ezdxf.audit import Auditor
Expand Down Expand Up @@ -159,7 +159,9 @@ def test_load_from_text(entity):
assert entity.dxf.insert == (0, 0, 0)


@pytest.mark.parametrize("txt,ver", [(ENTITY_R2000, DXF2000), (ENTITY_R12, DXF12)])
@pytest.mark.parametrize(
"txt,ver", [(ENTITY_R2000, const.DXF2000), (ENTITY_R12, const.DXF12)]
)
def test_write_dxf(txt, ver):
expected = basic_tags_from_text(txt)
attdef = TEST_CLASS.from_text(txt)
Expand Down Expand Up @@ -237,6 +239,11 @@ def test_set_mtext(self):
attrib.set_mtext(mtext)
assert attrib.has_embedded_mtext_entity is True

def test_discard_mtext(self, attrib):
attrib.discard_mtext()
assert attrib.has_embedded_mtext_entity is False
assert attrib.dxf.attribute_type == const.ATTRIB_TYPE_SINGLE_LINE

def test_transformation_of_embedded_mtext(self):
attrib = Attrib.new(dxfattribs={"color": 3, "text": "TEST"})
mtext = MText.new(dxfattribs={"color": 3})
Expand Down

0 comments on commit 05ca6ae

Please sign in to comment.