Skip to content

Instantly share code, notes, and snippets.

@amrit3701
Created March 17, 2019 08:31
Show Gist options
  • Select an option

  • Save amrit3701/ebdf91fa3db5e71e7a334ef38e4dcefa to your computer and use it in GitHub Desktop.

Select an option

Save amrit3701/ebdf91fa3db5e71e7a334ef38e4dcefa to your computer and use it in GitHub Desktop.
Comparison of reading IfcGloballyUniqueId from IFC in different OS

Below is the comparison of reading IfcGloballyUniqueId from IFC file by using ifcopenshell (Python2.7) in different OS.

Download IFC file: GND_TDP202.ifc

On Ubuntu:

root@98a1aa8ab4a9:/share# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic
root@98a1aa8ab4a9:/share# ipython
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
Type "copyright", "credits" or "license" for more information.

IPython 5.8.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import ifcopenshell as ifc

In [2]: f = ifc.open("GNE_TDP202.ifc")

In [3]: products = f.by_type("ifcproduct")

In [4]: products
Out[4]:
[#22=IfcSite('2oAZ$Cu_aHwBkVc2Blr0Hl',#5,'GNE College','',$,$,$,$,.ELEMENT.,(30,51,31),(75,51,37),0.245512,$,#21),
 #23=IfcBuilding('2oAZ$Du_aHwBkVc2Blr0Hl',#5,'Nanak Tower II','',$,$,$,$,.ELEMENT.,$,$,$),
 #108=IfcGrid('2oAZ$Fu_aHwBkVc2Blr0Hl',#5,'Axes','',$,#104,#107,(#27,#31,#35,#39),(#43,#47,#51,#55,#59,#63,#67,#71,#75,#79,#83,#87,#91,#95,#99,#103),$),
 #126=IfcBuildingStorey('2oAZ$Hu_aHwBkVc2Blr0Hl',#5,'Level 0','',$,$,$,$,.ELEMENT.,0.),
 #127=IfcBuildingElementProxy('2oAZ$Iu_aHwBkVc2Blr0Hl',#5,'WPProxy','',$,$,$,$,.ELEMENT.),
 #128=IfcBuildingStorey('2oAZ$Ju_aHwBkVc2Blr0Hl',#5,'Level 1','',$,$,$,$,.ELEMENT.,3.6),
 #129=IfcBuildingElementProxy('2oAZ$Ku_aHwBkVc2Blr0Hl',#5,'WPProxy001','',$,$,$,$,.ELEMENT.),
 #130=IfcBuildingStorey('2oAZ$Lu_aHwBkVc2Blr0Hl',#5,'Level 2','',$,$,$,$,.ELEMENT.,7.2),
 #131=IfcBuildingElementProxy('2oAZ$Mu_aHwBkVc2Blr0Hl',#5,'WPProxy002','',$,$,$,$,.ELEMENT.),
 #132=IfcBuildingStorey('2oAZ$Nu_aHwBkVc2Blr0Hl',#5,'Level 3','',$,$,$,$,.ELEMENT.,10.8),
 #133=IfcBuildingElementProxy('2oAZ$Ou_aHwBkVc2Blr0Hl',#5,'WPProxy003','',$,$,$,$,.ELEMENT.),
 #134=IfcBuildingStorey('2oAZ$Pu_aHwBkVc2Blr0Hl',#5,'Level 4','',$,$,$,$,.ELEMENT.,14.4),
 #135=IfcBuildingElementProxy('2oAZ$Qu_aHwBkVc2Blr0Hl',#5,'WPProxy004','',$,$,$,$,.ELEMENT.),
 #179=IfcAnnotation('2oAZ$du_aHwBkVc2Blr0Hl',#5,'Building Outline','',$,#9,#178),
 #187=IfcAnnotation('2oAZ$eu_aHwBkVc2Blr0Hl',#5,'Building Label','',$,#9,#186)]

In [5]: entity = products[0]

In [6]: entity
Out[6]: #22=IfcSite('2oAZ$Cu_aHwBkVc2Blr0Hl',#5,'GNE College','',$,$,$,$,.ELEMENT.,(30,51,31),(75,51,37),0.245512,$,#21)

In [7]: entity.GlobalId
Out[7]: u'\U006f0032\U005a0041\U00430024\U005f0075\U00480061\U00420077\U0056006b\U00320063\U006c0042\U00300072\U006c0048\x00\x03\x00\U3b99aea0\u55ef\x08\x00\U99b25b86\U5ba20919\x01\U626f6c47'

In [8]: str(entity.GlobalId)
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-8-d0d3229b11e1> in <module>()
----> 1 str(entity.GlobalId)

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-10: ordinal not in range(128)

On Mac OSx:

λ ~/ uname -a
Darwin Amritpals-MacBook-Pro.local 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64
λ ~/ ipython
Python 2.7.15 (default, Jan 12 2019, 21:07:57)
Type "copyright", "credits" or "license" for more information.

IPython 5.8.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import ifcopenshell as ifc

In [2]: f = ifc.open("GNE_TDP202.ifc")

In [3]: products = f.by_type("ifcproduct")

In [4]: products
Out[4]:
[#22=IfcSite('2oAZ$Cu_aHwBkVc2Blr0Hl',#5,'GNE College','',$,$,$,$,.ELEMENT.,(30,51,31),(75,51,37),0.245512,$,#21),
 #23=IfcBuilding('2oAZ$Du_aHwBkVc2Blr0Hl',#5,'Nanak Tower II','',$,$,$,$,.ELEMENT.,$,$,$),
 #108=IfcGrid('2oAZ$Fu_aHwBkVc2Blr0Hl',#5,'Axes','',$,#104,#107,(#27,#31,#35,#39),(#43,#47,#51,#55,#59,#63,#67,#71,#75,#79,#83,#87,#91,#95,#99,#103),$),
 #126=IfcBuildingStorey('2oAZ$Hu_aHwBkVc2Blr0Hl',#5,'Level 0','',$,$,$,$,.ELEMENT.,0.),
 #127=IfcBuildingElementProxy('2oAZ$Iu_aHwBkVc2Blr0Hl',#5,'WPProxy','',$,$,$,$,.ELEMENT.),
 #128=IfcBuildingStorey('2oAZ$Ju_aHwBkVc2Blr0Hl',#5,'Level 1','',$,$,$,$,.ELEMENT.,3.6),
 #129=IfcBuildingElementProxy('2oAZ$Ku_aHwBkVc2Blr0Hl',#5,'WPProxy001','',$,$,$,$,.ELEMENT.),
 #130=IfcBuildingStorey('2oAZ$Lu_aHwBkVc2Blr0Hl',#5,'Level 2','',$,$,$,$,.ELEMENT.,7.2),
 #131=IfcBuildingElementProxy('2oAZ$Mu_aHwBkVc2Blr0Hl',#5,'WPProxy002','',$,$,$,$,.ELEMENT.),
 #132=IfcBuildingStorey('2oAZ$Nu_aHwBkVc2Blr0Hl',#5,'Level 3','',$,$,$,$,.ELEMENT.,10.8),
 #133=IfcBuildingElementProxy('2oAZ$Ou_aHwBkVc2Blr0Hl',#5,'WPProxy003','',$,$,$,$,.ELEMENT.),
 #134=IfcBuildingStorey('2oAZ$Pu_aHwBkVc2Blr0Hl',#5,'Level 4','',$,$,$,$,.ELEMENT.,14.4),
 #135=IfcBuildingElementProxy('2oAZ$Qu_aHwBkVc2Blr0Hl',#5,'WPProxy004','',$,$,$,$,.ELEMENT.),
 #179=IfcAnnotation('2oAZ$du_aHwBkVc2Blr0Hl',#5,'Building Outline','',$,#9,#178),
 #187=IfcAnnotation('2oAZ$eu_aHwBkVc2Blr0Hl',#5,'Building Label','',$,#9,#186)]

In [5]: entity = products[0]

In [6]: entity
Out[6]: #22=IfcSite('2oAZ$Cu_aHwBkVc2Blr0Hl',#5,'GNE College','',$,$,$,$,.ELEMENT.,(30,51,31),(75,51,37),0.245512,$,#21)

In [7]: entity.GlobalId
Out[7]: u'2oAZ$Cu_aHwBkVc2Blr0Hl'

In [8]: str(entity.GlobalId)
Out[8]: '2oAZ$Cu_aHwBkVc2Blr0Hl'

Conclusion

When we read IfcGloballyUniqueId from IFC file on Ubuntu, it gives UnicodeEncodeError but on MacOSx ifcopenshell successfully parse IfcGloballyUniqueID (i.e. 2oAZ$Cu_aHwBkVc2Blr0Hl).

@amrit3701
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment