Skip to content

Commit

Permalink
add example for block with multiline-attrib
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed Dec 15, 2024
1 parent 1bc8afb commit 4b5e6d7
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion examples/blocks/insert_with_mtext_attrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,37 @@
CWD = pathlib.Path(".")


def main():
def block_definition_with_multiline_attdef():
doc = ezdxf.new(dxfversion="R2018")
block = doc.blocks.new(name="MY_BLOCK")

# Text, location and height not needed, because copied from MTEXT entity
attdef = block.add_attdef("TAG1")
# Define the multiline attribute as MTEXT entity
mtext = block.add_mtext("Default Value", dxfattribs={"char_height": 0.25})
mtext.set_location((0, 0))
# Set ATTDEF content from MTEXT entity
attdef.set_mtext(mtext)

attdef = block.add_attdef("TAG2", (0, -1))
# reuse existing MTEXT entity
mtext.text = "Another Default"
mtext.set_location((0, -1))
# Set ATTDEF content from MTEXT entity and destroy the MTEXT entity
attdef.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(CWD / "block_with_multiline_attdef.dxf")


def attach_multiline_attrib_to_block_reference():
doc = ezdxf.new(dxfversion="R2018")
# create a new block definition:
block = doc.blocks.new("TEST")
Expand All @@ -29,5 +59,10 @@ def main():
doc.saveas(CWD / "insert_with_mtext_attribute.dxf")


def main():
attach_multiline_attrib_to_block_reference()
block_definition_with_multiline_attdef()


if __name__ == "__main__":
main()

0 comments on commit 4b5e6d7

Please sign in to comment.