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

Remove \n's if exported to an .ODS. #4497

Closed
theoryshaw opened this issue Apr 2, 2024 · 4 comments
Closed

Remove \n's if exported to an .ODS. #4497

theoryshaw opened this issue Apr 2, 2024 · 4 comments
Labels

Comments

@theoryshaw
Copy link
Member

Would be nice if the \n would be removed, if exported to an .ODS.

Either that, or have the newline show in the .ODS.
Not sure the best approach.

image

image

@Moult
Copy link
Contributor

Moult commented Apr 9, 2024

This is a bit of a more subtle bug. Firstly, let's say an IFC text attribute contained a new line (e.g. Foo\nbar). Previously, that would be completely invisible to the user so the user would only ever see Foobar in Blender. After bcc67ec the user will now see Foo\nbar. Nice! The user can remove the new line or add new lines or whatever.

Now let's say you actually have a new line in your data. Will that be exported into ODS? Nope. We use Pandas' to_excel() function which uses odfpy which ... has a bug where newlines are ignored. But hey, at least it results in one of the possible desired scenarios in this bug. Note that if you export as Excel you will get a true newline.

In the future we can build our own ODS exporter like we already do in IfcFM and add the p tags necessary for new lines. That way xlsx and ods behaviour will be consistent.

Now the next issue ... your material names never had new lines in it. In fact, you actually had the literal \n, i.e. in IFC your material name would be Foo\\nbar (notice the double slash). The Blender live viewport annotations would treat this fake \\n as a new line which is not quite correct. So after bd5fd35 your existing fake \\n will no longer cause newlines and only true newlines will cause newlines.

What a mouthful. In short, run this script which'll convert your fakes to real newlines.

import ifcopenshell
f = ifcopenshell.open('/path/to/your/model.ifc')
for e in f.by_type("IfcMaterial"):
    e.Name = e.Name.replace("\\n", "\n")
f.write('/path/to/fixed.ifc')

@theoryshaw
Copy link
Member Author

Thanks @Moult!

I extended the script to catch the following too...

import ifcopenshell
f = ifcopenshell.open('/path/to/your/model.ifc')
for e in f.by_type("IfcMaterial"):
    e.Name = e.Name.replace("\\n", "\n")
for s in f.by_type("IfcSurfaceStyle"):
    s.Name = s.Name.replace("\\n", "\n")
for t in f.by_type("IfcTextLiteralWithExtent"):
    t.Literal= t.Literal.replace("\\n", "\n")
f.write('/path/to/fixed.ifc')

@theoryshaw
Copy link
Member Author

Had to add the following error exception to bypass some errors.

import ifcopenshell
f = ifcopenshell.open('/path/to/your/model.ifc')
for e in f.by_type("IfcMaterial"):
    e.Name = e.Name.replace("\\n", "\n")
for s in f.by_type("IfcSurfaceStyle"):
    s.Name = s.Name.replace("\\n", "\n")
for t in f.by_type("IfcTextLiteralWithExtent"):
    try:
        t.Literal= t.Literal.replace("\\n", "\n")
    except Exception as ex:
        print(f"Error modifying IfcTextLiteralWithExtent: {ex}")
f.write('/path/to/fixed.ifc')

@Moult
Copy link
Contributor

Moult commented Apr 9, 2024

Huh, I can only imagine the type of exception there to be if the literal was null, which shouldn't occur. There must be another hidden bug somewhere.

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

No branches or pull requests

2 participants