Skip to content
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

ELLIPSE should accept an axis ratio as small as 1e-10 #800

Closed
mozman opened this issue Dec 15, 2022 Discussed in #799 · 6 comments
Closed

ELLIPSE should accept an axis ratio as small as 1e-10 #800

mozman opened this issue Dec 15, 2022 Discussed in #799 · 6 comments

Comments

@mozman
Copy link
Owner

mozman commented Dec 15, 2022

Discussed in #799

Originally posted by dmkh1984 December 15, 2022
Good day.
I open document (try DXF2018 and DXF2010/2013 formats, works same), delete some entities with paperspace.delete_entity(entity) and try to save document with doc.save() and got broken file and this:
`Traceback (most recent call last):
File "F:\Scipts\Delete\Delete.py", line 35, in
doc.save()
File "C:\Users\PyDev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ezdxf\document.py", line 543, in save
self.write(fp, fmt=fmt) # type: ignore
File "C:\Users\PyDev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ezdxf\document.py", line 601, in write
self.export_sections(tagwriter)
File "C:\Users\PyDev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ezdxf\document.py", line 620, in export_sections
self.entities.export_dxf(tagwriter)
File "C:\Users\PyDev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ezdxf\sections\entities.py", line 111, in export_dxf
layouts.modelspace().entity_space.export_dxf(tagwriter)
File "C:\Users\PyDev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ezdxf\entitydb.py", line 391, in export_dxf
entity.export_dxf(tagwriter)
File "C:\Users\PyDev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ezdxf\entities\dxfentity.py", line 686, in export_dxf
self.export_entity(tagwriter)
File "C:\Users\PyDev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ezdxf\entities\ellipse.py", line 126, in export_entity
assert is_valid_ratio(self.dxf.ratio)

AssertionError`

Overall, great package, big thanks.

@mozman
Copy link
Owner Author

mozman commented Dec 15, 2022

I did some tests with DWG Trueview 2021 and the valid range for the axis-ratio also expands into the negative side and the lower limit of 1e-10 is also new to me: -1.0 ... -1e-10 and +1e-10 ... +1.0

EDIT: the valid negative range is also documented in my source code 😄

@mozman mozman changed the title ELLIPSE should accept negative axis ratios ELLIPSE should accept an axis ratio as small as 1e-10 Dec 15, 2022
@mozman
Copy link
Owner Author

mozman commented Dec 15, 2022

@dmkh1984 I'm not sure if this is really the solution, so the sample file would still be appreciated.

@dmkh1984
Copy link

Fun fact, after I delete all "sensitive" info, it works just fine. So, it seems that it got corrupted object. I will try to find this obj on
weekend and send file just with them.

@mozman
Copy link
Owner Author

mozman commented Dec 16, 2022

@dmkh1984 The problem is clearly the ratio attribute of the ELLIPSE entity. I only need this value and this script can save you some time:

import ezdxf

doc = ezdxf.readfile("your.dxf")
for e in doc.entitydb.values():
    if e.dxftype() == "ELLIPSE":
        print(f"Ellipse axis-ratio: {e.dxf.ratio}")

Please post the output of this script here.

@dmkh1984
Copy link

dmkh1984 commented Dec 16, 2022

I slightly update script:

import ezdxf

doc = ezdxf.readfile("Delete_Target.dxf")
print("Work start")
for e in doc.entitydb.values():
    if e.dxftype() == "ELLIPSE":
        print(f"Ellipse #{e} axis-ratio: {e.dxf.ratio}")
print("Work end")

That I get it's a lot, so I save output to file (attached)
Output.txt

@mozman
Copy link
Owner Author

mozman commented Dec 16, 2022

Thank you - it was really the lower bound of 1e-6 for the axis-ratio which caused the issue and this is fixed now.

@mozman mozman closed this as completed Dec 16, 2022
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

2 participants