Replies: 4 comments 1 reply
-
Hi! Again #942: Multi-line attributes were introduced in DXF R2018 and are not documented. Avoid them if you can. Multi-line attributes are not supported by the methods There is one example how to add multi-line attributes to INSERT entities: import ezdxf
def main():
doc = ezdxf.new(dxfversion="R2018")
# create a new block definition:
block = doc.blocks.new("TEST")
block.add_circle((0, 0), 1)
msp = doc.modelspace()
# create a block reference in modelspace:
insert = msp.add_blockref("TEST", (0, 0))
# add a single line attribute to the block reference:
attrib = insert.add_attrib("ATT0", "dummy")
# create a MTEXT entity:
m_text = msp.add_mtext("test1\ntest2\ntest3")
m_text.set_location((5, 5))
# embed the MTEXT entity into the attribute:
attrib.embed_mtext(m_text)
doc.saveas("insert_with_mtext_attribute.dxf")
if __name__ == "__main__":
main() You have to do everything manually:
An ATTRIB entity does not require an ATTDEF entity in the BLOCK definition, the ATTDEF is just a template to create new ATTRIB entities. |
Beta Was this translation helpful? Give feedback.
-
Editing the embedded import pathlib
import ezdxf
from ezdxf.entities import Insert
from ezdxf.math import Matrix44
CWD = pathlib.Path("~/Desktop/Outbox").expanduser()
if not CWD.exists():
CWD = pathlib.Path(".")
DOC_0 = CWD / "source_mtext_attribute.dxf"
DOC_1 = CWD / "edit_mtext_attribute.dxf"
DOC_2 = CWD / "move_insert_and_attrib.dxf"
DOC_3 = CWD / "move_attribute_without_insert.dxf"
def make_doc():
doc = ezdxf.new(dxfversion="R2018")
block = doc.blocks.new("TEST")
block.add_circle((0, 0), 1)
msp = doc.modelspace()
insert = msp.add_blockref("TEST", (0, 0))
attrib = insert.add_attrib("ATT0", "dummy")
m_text = msp.add_mtext("test1\ntest2\ntest3")
m_text.set_location((5, 5))
attrib.embed_mtext(m_text)
doc.saveas(DOC_0) Editing the embedded def edit_multiline_attrib():
doc = ezdxf.readfile(DOC_0)
insert: Insert = doc.query("INSERT").first
attrib = insert.get_attrib("ATT0")
if attrib.has_embedded_mtext_entity:
# extract the embedded MTEXT entity
mtext = attrib.virtual_mtext_entity()
# modify the content
mtext.text += "\nline4" # text is not in the DXF namespace!
# set absolut location
mtext.dxf.insert = (5, 5)
# copy modified MTEXT content to ATTRIB
attrib.set_mtext(mtext)
doc.saveas(DOC_1) Transform the INSERT and the ATTRIB entity at once - this works with the next release v1.1.2, because the current release has a bug: def move_insert_and_attrib():
doc = ezdxf.readfile(DOC_0)
insert: Insert = doc.query("INSERT").first
insert.transform(Matrix44.translate(0, -5, 0))
doc.saveas(DOC_2) Transform only the ATTRIB entity - this works with the next release v1.1.2, because the current release has a bug: def move_attrib_only():
doc = ezdxf.readfile(DOC_0)
insert: Insert = doc.query("INSERT").first
attrib = insert.get_attrib("ATT0")
attrib.transform(Matrix44.translate(0, 5, 0))
doc.saveas(DOC_3) Executing the code: if __name__ == "__main__":
make_doc()
edit_multiline_attrib()
move_insert_and_attrib()
move_attrib_only() Source code: |
Beta Was this translation helpful? Give feedback.
-
Mozman, thank you so much for showing in such detail how you can work with these blocks using other means. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Dear developer!!!, please tell me in version 1.1.1 of the library there are only 2 methods for inserting a block into a model???
add_blockref(name: str, insert: UVec, dxfattribs=None)→ Insert
add_auto_blockref(name: str, insert: UVec, values: dict[str, str], dxfattribs=None)→ Insert
in the first method I simply insert a block, and in the second I can immediately set the attribute values to be passed if they are in the block.
Why, if the created block with multi-line text, when using the second method, turns into an attribute with single-line text???
Now how can this be solved?? if I strictly want to create blocks in a CAD program with multi-line text, and using your library they need to be placed and filled with attributes.
Or is this not possible now?
Beta Was this translation helpful? Give feedback.
All reactions