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

Encoding error : wstring_convert::to_bytes #1322

Closed
bdaniere opened this issue Feb 16, 2021 · 1 comment
Closed

Encoding error : wstring_convert::to_bytes #1322

bdaniere opened this issue Feb 16, 2021 · 1 comment

Comments

@bdaniere
Copy link

Hi,

I'm encountering encoding problems when opening IFC files.
Problems were not detected at the time of reading but prevent some treatments afterward:
(I've put the few errors in a sample_wall.ifc as an attachment)
simple_wall.zip

ifc_file = ifcopenshell.open("/home/simple_wall.ifc")
ifc_file[4]

  File "ifcopenshell_tools/ifcopenshell/entity_instance.py", line 164, in __repr__.
    return repr(self.wrapped_data)
  File "ifcopenshell_tools/ifcopenshell/ifcopenshell_wrapper.py", line 1659, in __repr__.
    return _ifcopenshell_wrapper.entity_instance___repr__(self)
RuntimeError: wstring_convert::to_by

For the moment, these blocking problems concern 3 characters :
- "°": I added it on the IfcWall instance n° 45
- "Ø": I added it on the IfcPerson instance n° 4
- "é": I added it on the IfcWindow instance n° 124

This error is then found with IfcConvert (IfcOpenShell IfcConvert 0.6.0b0 (OCC 7.3.0)) :

...
terminate called after throwing an instance of 'std::range_error'.
  what(): wstring_convert::to_bytes

Do you have an idea of how to solve/counteract the problem?
Thank you

@aothms
Copy link
Member

aothms commented Feb 17, 2021

It's not valid in IFC(-SPF) to have character bytes above 0x7e. It's strictly ASCII. It needs to be encoded in a special way using code pages or \X2 / \X4 for unicode, see below:

>>> import ifcopenshell
>>> f = ifcopenshell.file()
>>> f.createIfcPerson('°')
#1=IfcPerson('°',$,$,$,$,$,$,$)
>>> f.write('test.ifc')
>>> print(open('test.ifc').read())
ISO-10303-21;
HEADER;
FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1');
FILE_NAME('','2021-02-17T15:02:37',(),(),'IfcOpenShell 0.6.0b0','IfcOpenShell 0.6.0b0','');
FILE_SCHEMA(('IFC4'));
ENDSEC;
DATA;
#1=IFCPERSON('\X2\00B0\X0\',$,$,$,$,$,$,$);
ENDSEC;
END-ISO-10303-21;

@bdaniere bdaniere closed this as completed Mar 5, 2021
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