You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ezdxf=v1.3.5
I'm having problems with attributes and multi-line text again.
In the first step I create a block with multi-line text using your method.
Next, I want to change the value of the text in an already created document.
The software seems to change everything, but when viewing it nothing changes.
importezdxffromezdxf.entities.insertimportInsert# STEP 1doc=ezdxf.new(dxfversion="R2018")
block=doc.blocks.new(name="MY_BLOCK")
# Text, location and height not needed, because copied from MTEXT entityattdef=block.add_attdef("TAG1")
# Define the multiline attribute as MTEXT entitymtext=block.add_mtext("Default Value", dxfattribs={"char_height": 0.25})
mtext.set_location((0, 0))
# Set ATTDEF content from MTEXT entityattdef.set_mtext(mtext)
attdef=block.add_attdef("TAG2", (0, -1))
# reuse existing MTEXT entitymtext.text="Another Default"mtext.set_location((0, -1))
# Set ATTDEF content from MTEXT entity and destroy the MTEXT entityattdef.embed_mtext(mtext)
# Usage of add_auto_attribs() with multiline ATTDEFs:msp=doc.modelspace()
insert=msp.add_blockref("MY_BLOCK", insert=(5, 5))
attribs= {
"TAG1": "TAG1-Line1\nTAG1-Line2",
"TAG2": "TAG2-Line3\nTAG2-Line4",
}
insert.add_auto_attribs(attribs)
doc.saveas("block_with_multiline_attdef.dxf")
# STEP 2doc=ezdxf.readfile("block_with_multiline_attdef.dxf")
msp=doc.modelspace()
insert_all=msp.query("INSERT")
forinsertininsert_all:
insert:Inserttext_atr=insert.get_attrib_text("TAG1")
print(f"OLD text: {text_atr}")
text_new="\\W0.8;NEW TEXT"atr=insert.get_attrib("TAG1")
atr.dxf.text=text_newprint(f"NEW text: {atr.plain_text()}")
doc.saveas("block_with_multiline_attdef.dxf")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Ezdxf=v1.3.5
I'm having problems with attributes and multi-line text again.
In the first step I create a block with multi-line text using your method.
Next, I want to change the value of the text in an already created document.
The software seems to change everything, but when viewing it nothing changes.
Print -
OLD text: TAG1-Line1
NEW text: \W0.8;NEW TEXT
Open doc -
Beta Was this translation helpful? Give feedback.
All reactions