-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set_mtext_content() doesn't work for "annotative" MULTILEADER #840
Comments
Use Check for MTEXT content |
Thank you reply. I try, then the entity is not have BLOCK. But I Can't write by set_mtext_content(). I try change simple code.
Is there anything else I could try? |
Run this script: from __future__ import annotations
import pathlib
import ezdxf
from ezdxf.math import Vec2
CWD = pathlib.Path("~/Desktop/Outbox").expanduser()
if not CWD.exists():
CWD = pathlib.Path(".")
def quick_mtext_horizontal():
doc = ezdxf.new(setup=True)
mleaderstyle = doc.mleader_styles.duplicate_entry("Standard", "EZDXF")
mleaderstyle.set_mtext_style("OpenSans")
msp = doc.modelspace()
ml_builder = msp.add_multileader_mtext("EZDXF")
ml_builder.quick_leader(
"Line1\nLine2",
target=Vec2(40, 15),
segment1=Vec2.from_deg_angle(45, 14),
)
mleader = msp.query("MULTILEADER").first
mleader.set_mtext_content("New Content")
doc.set_modelspace_vport(60, center=(10, 5))
doc.saveas(CWD / "mleader.dxf")
if __name__ == '__main__':
quick_mtext_horizontal() The result should look like that in your DXF viewer: |
Thank you. I understand that set_mtext_content() works in the situation of creating a new mleader ;) The next step I want to do is to make changes to the mtext in an already existing mleader. Best regards, |
The changing part works the same way for new and existing MULTILEADER, but you have to know where they are located: the modelspace, a paperspace or a block definition. This depends on your input file. |
I created a simple test file and tried it, and confirmed that the changes could be applied to an existing MULTILEADER. However, it could not be applied to the file used in the first job I tried. It seems that |
Please show an example including code and (zipped) DXF data. |
Thank you. This is my script code. #!/usr/bin/env python3
# usage: dxfrep <from> <to> <file>
##################################################
# IMPORT
import sys
import ezdxf
from ezdxf.entities.text import Text
from ezdxf.entities.mtext import MText
from ezdxf.entities.mleader import MultiLeader
##################################################
# MAIN
fromString = sys.argv[1]
toString = sys.argv[2]
dxf = ezdxf.readfile(sys.argv[3])
for entity in dxf.entities:
if type(entity) is Text:
## This is file. ##
entity.dxf.text = entity.plain_text().replace(fromString, toString)
if type(entity) is MText:
## This is file. ##
entity.text = entity.plain_text().replace(fromString, toString)
if isinstance(entity, MultiLeader):
## This is fine. ##
print( entity.get_mtext_content().replace(fromString, toString) )
## Not working this for Annonative. ##
## I want to replace and write back text for Annonative-MultiLeader. ##
entity.set_mtext_content( entity.get_mtext_content().replace(fromString, toString) )
dxf.saveas("out.dxf") I run this on shell. $ dxfrep TEST @@@ test.dxf This is my test file what maked by AutoCAD 2023. Best regards, |
I don't know how the annotative mode works, the MULTILEADER entity contains only the new text but BricsCAD and Trueview shows the old text even when the proxy graphic was deleted. The only solution I found is to set annotative to doc = ezdxf.readfile("test.dxf")
msp = doc.modelspace()
for e in msp.query("MULTILEADER"):
e.set_mtext_content("EZDXF")
e.dxf.is_annotative = False
e.update_proxy_graphic() # current implementation just deletes the proxy graphic
doc.saveas("out.dxf") UPDATE: Updating the proxy graphic is important when changing the appearance of the MULTILEADER entity in any kind, some applications e.g the |
Describe the bug
I want to replace text in MultiLeader.
I get text by get_mtext_content() is ok, but i can't changging for MText in MultiLeader.
my script
Expected behavior
I thought this code would allow me to replace text in text, mtext, and mleader in dxf. But does not work "set_mtext_content()" for mleader.
The text was updated successfully, but these errors were encountered: