GithubHelp home page GithubHelp logo

Comments (9)

mozman avatar mozman commented on August 21, 2024 1

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:

image

from ezdxf.

mozman avatar mozman commented on August 21, 2024

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.

nullplus avatar nullplus commented on August 21, 2024

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.

nullplus avatar nullplus commented on August 21, 2024

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.

mozman avatar mozman commented on August 21, 2024

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.

nullplus avatar nullplus commented on August 21, 2024

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.

mozman avatar mozman commented on August 21, 2024

Please show an example including code and (zipped) DXF data.

from ezdxf.

nullplus avatar nullplus commented on August 21, 2024

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.

mozman avatar mozman commented on August 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.