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: GNE_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)
 in ()
----> 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).

Parsing functionality of IfcOpenShell in detail

The parsing functionality is a very interesting feature of IfcOpenShell-python. It enables the user to extract information of his/her interest from a .ifc file. For eg. in the below example, we will extract NominalDiameter, CrossSectionArea etc of reinforcing bar from .ifc file using python interactive shell.

In IfcOpenShell-python there are two main functions present.

  1. by_type(<argument>): This enable the user to what type of information (i.e. IfcProject, IfcRoot, IfcSlab etc.) you want to extract from .ifc file. Arguments name is same as all the entities present in IFC2x4 (http://www.buildingsmart-tech.org). For eg. if user want to extract a information of “IfcWall” then they simple put “IfcWall” as argument.
  2. is_a(): We can use this function in two different ways. For eg. if we use is_a() without any argument then it only tell that information present is belonging to which entity or if we use is_a("IfcWall") with one argrument then it will simply check whether the argument name is same or not with entity name of data present in the form of True or False.

Note: Rest of the classes, functions and there arguments name are same as present in IFC2x4. You can understand more in the below example.

Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> # Importing ifcopenshell                                            
>>> import ifcopenshell                                                 
>>> # Openning .ifc file using open() fuction which is present in ifcopenshell library 
>>> file = ifcopenshell.open("Slab.ifc")                                
>>> # Here we use by_type() function because we want to extract information of IfcReinforcingBar from .ifc file 
>>> rebars = file.by_type("IfcReinforcingBar")                          
>>> # All the rebars present in the .ifc file is store in rebars variable in the form of array
>>> rebars                                                              
>>> [#218=IfcReinforcingBar('3jNYnJqWb9afBZKX5CCrhW',#41,'Rebar Bar:NC Rebar : Shape M_00:390027: 1',$,'Rebar Bar:NC Rebar:53673',#201,#216,'390027',$,16.,0.000201061929829747,5920.,.NOTDEFINED.,$),
 #251=IfcReinforcingBar('3jNYnJqWb9afBZKX9CCrhW',#41,'Rebar Bar:NC Rebar : Shape M_00:390027: 2',$,'Rebar Bar:NC Rebar:53673',#250,#248,'390027',$,16.,0.000201061929829747,5920.,.NOTDEFINED.,$),
 #270=IfcReinforcingBar('3jNYnJqWb9afBZKXDCCrhW',#41,'Rebar Bar:NC Rebar : Shape M_00:390027: 3',$,'Rebar Bar:NC Rebar:53673',#269,#267,'390027',$,16.,0.000201061929829747,5920.,.NOTDEFINED.,$)]
>>> rebar = rebars[0]                                                   
>>> rebar                                                               
>>> #218=IfcReinforcingBar('3jNYnJqWb9afBZKX5CCrhW',#41,'Rebar Bar:NC Rebar : Shape M_00:390027: 1',$,'Rebar Bar:NC Rebar:53673',#201,#216,'390027',$,16.,0.000201061929829747,5920.,.NOTDEFINED.,$)
>>> # Extracting actual data of rebar. Here you will find all the list of arguments present in IfcReinforcingBar (http://www.buildingsmart-tech.org/ifc/IFC2x4/alpha/html/ifcstructuralelementsdomain/lexical/ifcreinforcingbar.htm) 
>>> rebar.NominalDiameter                                               
>>> 16.0                                                                
>>> rebar.CrossSectionArea                                              
>>> 0.000201061929829747                                                
>>> rebar.BarLength                                                     
>>> 5920.0                                                              
>>> rebar.BarRole                                                       
>>> 'NOTDEFINED'                                                        
>>> rebar.BarSurface                                                    
>>> rebar.OwnerHistory                                                  
>>> #41=IfcOwnerHistory(#38,#5,$,.NOCHANGE.,$,$,$,1488377749)           
>>> hist = rebar.OwnerHistory                                           
>>> # Using is_a() function to find the data present in hist variable is belonging to which entity
>>> hist.is_a()                                                         
>>> 'IfcOwnerHistory'                                                   
>>> # Here we check whether a data is belonging to specific entities or not
>>> hist.is_a("IfcOwnerHistory")                                        
>>> True                                                                
>>> hist.is_a("IfcWall")                                                
>>> False                                                               
>>> exit()  

Get sample IFC file Slab.ifc.

Reference:
http://academy.ifcopenshell.org/using-the-parsing-functionality-of-ifcopenshell-interactively
http://www.buildingsmart-tech.org/ifc/IFC2x4/alpha/html/ifcstructuralelementsdomain/lexical/ifcreinforcingbar.htm