Comments (9)
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:
from ezdxf.
Use isinstance(entity, MultiLeader)
instead of type(entity) == MultiLeader
, because your implementation doesn't process the MLEADER synonym.
Check for MTEXT content entity.has_mtext_content
, the entity may have BLOCK content.
from ezdxf.
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.
But not working.
if isinstance(entity, MultiLeader):
entity.set_mtext_content("@@@")
Is there anything else I could try?
from ezdxf.
Thank you.
I try and get same result dxf.
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.
Can you give me an example script on how to make changes to an already existing mleader?
Best regards,
from ezdxf.
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.
from ezdxf.
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 set_mtext_content()
is not executed for MULTILEADER with 'Annonative' set. What can i do?
The get_mtext_content()
works fine.
from ezdxf.
Please show an example including code and (zipped) DXF data.
from ezdxf.
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,
from ezdxf.
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 False
:
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:
The annotative feature is very complex and not documented in the DXF reference, therefore it is not supported by ezdxf
, setting ìs_annotative
to False
is the only supported solution.
Updating the proxy graphic is important when changing the appearance of the MULTILEADER entity in any kind, some applications e.g the drawing
add-on of ezdxf
show only the proxy graphic, because rendering the MULTILEADER entity is time consuming. The update method is not called automatically because in the future ezdxf
may be able to create the proxy graphic and this should be done only once when the modifying process is finished.
from ezdxf.
Related Issues (20)
- matplotlib raises exception in drawing add-on HOT 3
- DIMENSION cannot modify text HOT 3
- I try to get the text in the dwg, But the returned data is similar to Unicode,How can I get the normal text?
- add_spline methods not rendering correctly when using decimal points HOT 2
- Error with matplotlib backend when rendering Japanese whitespace to PNG HOT 2
- Autocad doesn't automatically render hatches
- entity.dxf.invisible = 1 ignored / not exported HOT 1
- Some tests fail when EZDXF_DISABLE_C_EXT=1 is set HOT 2
- Revcloud HOT 1
- Some DXF files generated by ezdxf 1.2.0 cannot be opened by AutoCAD HOT 1
- Idea: enable customization of ACI RGB values for drawing add-on export HOT 1
- Rendering of filled paths in viewports is broken HOT 1
- dxf2png get white background
- Curvature radius along a Spline
- Unicode not rendering properly HOT 10
- Cannot read ACAD_TABLE in DXF 2004 Format HOT 2
- .stb file won't parse HOT 5
- explode "ACAD_PROXY_ENTITY" , error: required argument is not a float HOT 4
- Problems with hidden objects when converting png HOT 11
- Read messed up LAYOUT structure created by QGIS HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ezdxf.