Skip to main content
Solved

IFC Invalid File Format error for IFC file, I think it is a character encoding error

  • September 7, 2020
  • 2 replies
  • 161 views

Forum|alt.badge.img

I am trying to open an IFC file from a client but I keep getting a syntax error:

ISO10303-21: The input data file has a syntax error in instance '#105':
syntax error, unexpected P21_TOK_STD_KEYWORD, expecting ')'
ISO10303-21: Invalid file format, unable to continue reading
A fatal error has occurred. Check the logfile above for details

I looked up this element (#105) using Python ifcopenshell, and found that it is an IfcPostalAddress element. I've modified the content below so it is not the original address, but I have left in the word "États-Unis" (French for "United States), because I believe this is what is causing the syntax error.

"#105= IFCPOSTALADDRESS($,$,$,$,('123 Fake Street, Faketown, FS 01234 Ã\x89tats-Unis'),$,'','','','User Defined');\n"

I thought I would be able to fix it by re-encoding it to utf-8 and saving it appropriately (Python snippet below):

with open(out_file, "w", encoding="utf-8") as f_out:
    with open(in_file, encoding="latin1") as f_in:
        for line in f_in.readlines():
            f_out.write(line.encode("latin1").decode("utf-8"))

I checked the file afterwards and it seems to be intact, but with the correct characters.

 

But I still get the same error. I tried opening the file with both "IFC with Data Views" and "Industry Foundation Class STEP/XML Files (IFC)" Readers. The first one puts the Feature Types on the workspace but fails upon running. The second one fails before putting the Feature Types on the workspace.

 

Does anyone have any idea on what else I can try?

Best answer by daveatsafe

Hi @iboates​ ,

 

The following link specifies the correct method for including extended characters in IFC:

https://technical.buildingsmart.org/resources/ifcimplementationguidance/string-encoding/

 

In your case, the string should be:

  1. "#105= IFCPOSTALADDRESS($,$,$,$,('123 Fake Street, Faketown, FS 01234 \\X\\C9tats-Unis'),$,'','','','User Defined');\\n"

or:

  1. "#105= IFCPOSTALADDRESS($,$,$,$,('123 Fake Street, Faketown, FS 01234 \\X2\\00C9\\X0\\tats-Unis'),$,'','','','User Defined');\\n"

 

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

daveatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • Best Answer
  • September 8, 2020

Hi @iboates​ ,

 

The following link specifies the correct method for including extended characters in IFC:

https://technical.buildingsmart.org/resources/ifcimplementationguidance/string-encoding/

 

In your case, the string should be:

  1. "#105= IFCPOSTALADDRESS($,$,$,$,('123 Fake Street, Faketown, FS 01234 \\X\\C9tats-Unis'),$,'','','','User Defined');\\n"

or:

  1. "#105= IFCPOSTALADDRESS($,$,$,$,('123 Fake Street, Faketown, FS 01234 \\X2\\00C9\\X0\\tats-Unis'),$,'','','','User Defined');\\n"

 

 


Forum|alt.badge.img
  • Author
  • September 10, 2020

Hi @iboates​ ,

 

The following link specifies the correct method for including extended characters in IFC:

https://technical.buildingsmart.org/resources/ifcimplementationguidance/string-encoding/

 

In your case, the string should be:

  1. "#105= IFCPOSTALADDRESS($,$,$,$,('123 Fake Street, Faketown, FS 01234 \\X\\C9tats-Unis'),$,'','','','User Defined');\\n"

or:

  1. "#105= IFCPOSTALADDRESS($,$,$,$,('123 Fake Street, Faketown, FS 01234 \\X2\\00C9\\X0\\tats-Unis'),$,'','','','User Defined');\\n"

 

 

Thanks, that's it