Skip to content

MTEXT entities not correct on ezdxf view #855

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

Closed
IvanKachaikinCendas opened this issue Mar 28, 2023 · 6 comments
Closed

MTEXT entities not correct on ezdxf view #855

IvanKachaikinCendas opened this issue Mar 28, 2023 · 6 comments

Comments

@IvanKachaikinCendas
Copy link

Hi @mozman! First of all, thanks once again for your amazing package that makes my life much easier :)

However, I'm facing a little error with one plan. More specifically, while openning the following file with ezdxf view, the content does not look the same as in AutoCAD.

To Reproduce
Information and data needed to reproduce the error:

  1. A simplified Python script which triggers the error: ezdxf view bad_xref.dxf
  2. Information about the ezdxf version and the OS: ezdxf == 1.0.3, Windows 11.
  3. A DXF to reproduce:
    bad_xref.zip

Expected behavior
In ideal case, I would expect that it looks just as in AutoCAD :)

Screenshots

  1. AutoCAD view:
    autocad-view-broken-xref
  2. ezdxf view view:
    ezdxf-view-broken-xref

P.S.: not sure if you are going to fix this issue right now or if it is in general fixable as it may be a bit weird and actually some strange AutoCAD behaviour. In any case thanks for checking it out and for any feedback 🙏

@mbway
Copy link
Contributor

mbway commented Mar 28, 2023

Is the issue here that layers are visible in ezdxf that are invisible by default in autocad?
As-in, if you toggle the layer visibility on the right of the ezdxf viewer are you able to get the view looking the same as autocad?

@mozman
Copy link
Owner

mozman commented Mar 29, 2023

This issue is caused by using absolute inline sizing parameters in the MTEXT entity.

The MTEXT entity in the BLOCK definition has a absolute height definition of H150 and the BLOCK is scaled by a factor of 0.001. The absolute text size is not adjusted when creating the virtual entities from the BLOCK definition. This has to be done in the MText.transform() method:

  • check if text scaling is required
  • fast check if absolute text sizes are present to avoid the slow part in most cases
  • slow part if adjustment is required:
    • parse the MTEXT content regex search and replace
    • adjust absolute text sizes:
      • H absolute text height in drawing units
      • T absolute char spacing (tracking) T is just a factor like the width factor
      • p absolute paragraph parameters: indentation and tab stops tab stops and indentation are factors of text height
    • recompile the MTEXT content

EDIT: MULTILEADER with MTEXT context is also affected by this issue

The inline resizing feature seems to be rarely used as this is the first reported issue for it and even BricsCAD has some issues:

viewing is correct:
image

but doesn't apply the scaling when exploding the block reference:
image

@IvanKachaikinCendas
Copy link
Author

Hi @mozman! Thanks a lot for your feedback as well as for the commits with fixes :)

By the way, this issue was also caused by transform method I presume. Recreated the files a little bit, so they may look a bit different than before, but nevertheless the case that I tried:

  • Took the plan bad_xref_1.zip, opened in AutoCAD and with ezdxf view, it looks the same:
    - AutoCAD view
    bad-xref-1-auto
    - ezdxf view view
    bad-xref-1-ezdxf
  • Run the following code
import ezdxf
from ezdxf.math import Matrix44

drawing = ezdxf.readile('bad_xref_1.dxf')
msp = drawing.modelspace()
xref = msp[0]

first_shift = Matrix44.translate(100.0, 100.0, 0.0)
rescale = Matrix44.scale(100.0)
second_shift = Matrix44.translate(-200.0, -200.0, 0.0)
transformation_matrix = Matrix44.chain(first_shift, rescale, second_shift)
inversed_transformation_matrix = transformation_matrix.copy()
inversed_transformation_matrix.inverse()

xref.transform(inversed_transformation_matrix)
xref.move_to_layout(drawing.layouts.get('Empty'))
xref.move_to_layout(msp)

drawing.saveas('bad_xref_1_transformed.dxf')
  • Took the resaved plan bad_xref_1_transformed.zip and reopened it in AutoCAD and with ezdxf view, and now it starts look strange:
    - AutoCAD view:
    bad-xref-1-transformed-auto
    - ezdxf view view:
    bad-xref-1-transformed-ezdxf

P.S.: not sure if there actually is something to fix in transform method, but thought that you may find it interesting :) Please let me know whether we may close this issue 😋

@IvanKachaikinCendas
Copy link
Author

IvanKachaikinCendas commented Apr 3, 2023

@mbway I always check it before creating issues here, but unfortunately it isn't the case: everything is visible here and in AutoCAD view you may see the problematic MTEXT entities as well, they are just too small, so that it is easy to not notice them. So the issue should normally be in the problem that @mozman described. In any case, thanks for your feedback! :)

@mozman
Copy link
Owner

mozman commented Apr 3, 2023

@IvanKachaikinCendas you have to update to the latest version on github, the file bad_xref_1_transformed.dxf looks like this with the ezdxf view command:

image

@IvanKachaikinCendas
Copy link
Author

@mozman Correct, right now it looks correctly. Thanks once again for fixing it! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants