Menu

encoding of utf8 ?

Help
2022-08-10
2022-08-10
  • Mathias Worm

    Mathias Worm - 2022-08-10

    Hello all together,

    I really hope this is the right place to post my question and anyone can help. I am working with ifcopenshell0.6 for python 2.7 on Ubuntu.

    Currently I am stuck with the encoding of the property RepresentationType:
    *
    RepresentationType = product.Representation.Representations[1].RepresentationType
    RepresentationType2 = product.Representation.Representations[1].getinfo()['RepresentationType']*

    I expect those values to be "SweptSolid" but the value I read is:
    *u'\U00770053\U00700065\U00530074\U006c006f\U00640069\x00\x80\x01\U006f004c\U0067006e'
    *
    No matter what decoding of encoding I have tried, I don#t get "SweptSolid".
    What I figured out until now is that its independent of the ifc version used (2x3 or 4).

    I really hope anyone can help me!

    Best,
    Mathias

     
  • Thomas Krijnen

    Thomas Krijnen - 2022-08-10

    With python 2.7 you need to be careful to select the 2.7 or 2.7u. You have the wrong version. Before version 3.3 python had a compile time setting to use either 16bit or 32bit fixed unicode code points. For 0.6 we still provide both variants, for 0.7 we don't provide builds anymore for 2.7 because it's eol. https://github.com/IfcOpenBot/IfcOpenShell/commit/721fe4729aa5302efe1602971aae2558934ad098#comments

     
  • Thomas Krijnen

    Thomas Krijnen - 2022-08-10

    Edit: for fun, if you take the string you reported and strip out the \U you can recover the value your after:

    >>> s = "007700530070006500530074006c006f00640069"
    >>> chars = [chr(int(s[i:i+2], 16)) for i in range(2, len(s), 4)]
    >>> "".join(map(lambda t: "".join(t), zip(chars[1::2], chars[::2])))
    'SweptSolid'
    
     
  • Mathias Worm

    Mathias Worm - 2022-08-10

    Hello Thomas,

    thanks a lot for your help, you solved my problem. I am "new" to the world of Python and had trouble finding the actual problem. But it was the wrong version as you mentioned. But still nice to see the other solution.

    thanks for this nice piece of software

    Best
    Mathias

     

Log in to post a comment.