Enhancing the power of rebar object – FreeCAD

Today, I added a Total Length property to the rebar object. Total length is the length of the individual rebar multiplied by the number of occurrences of the rebar. Below is a screenshot of rebar object properties. See the Length and Total Length property in property value table.


Yesterday, I also had a discussion with Sean regarding GCI tasks. He told about interoperability task (for eg. export FreeCAD model to BRL-CAD).

Adding Length property in the rebar object – FreeCAD

Today, I introduced a new property in the rebar object of FreeCAD i.e. Length. This property calculates the total length of the rebar. The user will see this property in the property value table. This property is very useful for Bar bending schedule.

Below is the code which calculates the length of rebar:

def getLengthOfRebar(rebar):
    """ getLengthOfRebar(RebarObject): Calculates the length of the rebar."""
    base = rebar.Base
    # When rebar is derived from DWire
    if hasattr(base, "Length"):
        return base.Length
    # When rebar is derived from Sketch
    elif base.isDerivedFrom("Sketcher::SketchObject"):
        length = 0
        for geo in base.Geometry:
            length += geo.length()
        return length
        FreeCAD.Console.PrintError("Cannot calculate rebar length from its base object\n")
        return None

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.