The IFC module

The IFC module's IFCExport() function provides a parametric equivalent to exporting an IFC2x3 model using Export Model . A Export Model software license is required for the IFCExport() function to Run properly in a parametric.

Here's an example of a script :

# creates calcs for all the members in job,

from version import CurrentVersion, VersionCompare
curr_version = CurrentVersion()
if VersionCompare( curr_version, '7.301' ) >= 0:
from IFC import IFCExport

from member import *
from dialog import Dialog
from dialog.entry import Entry
from dialog.checkbox import Checkbox
from dialog.choose_file import ChooseFile
from Point3D import *
import os

mems = MultiMemberLocate("Locate members to export to IFC")

class DialogObject:
    holes = False
    bolts = False
    welds = False

    file_name = "IFC_Test.ifc"
    path = "./output"

obj = DialogObject()
Dialog0 = Dialog( "IFC export" )
fs = ChooseFile( Dialog0, 'path', label= "Select Directory")
Entry( Dialog0, 'file_name', str )
Checkbox( Dialog0, 'holes', "Export holes" )
Checkbox( Dialog0, 'bolts', "Export bolts" )
Checkbox( Dialog0, 'welds', "Export welds" )
Dialog0.model = [obj]
dd = Dialog0.done()

if os.path.isdir( obj.path) == False:
    os.mkdir( obj.path )

m_nums = []

for m in mems:
    m_nums.append( m.MemberNumber )

IFCExport( m_nums, obj.file_name, obj.path, obj.holes, obj.bolts, obj.welds,
                    False, False, "", Point3D(0.,0.,0.), 0.0 )

To get help on the IFC module, you can use the SDS2 Python Prompt and the built-in Python functions dir() and help() :

SDS2 Python Prompt

>>> import IFC                                          # import the module
>>>
>>> dir(IFC)                                               # do a dir() on the module name
['IFCExport', '__doc__', '__name__', '__package__']
>>>
>>> help(IFC.IFCExport)                          # help on Hash
Help on built-in function IFCExport:

IFCExport(...)
C++ signature :                                            # see the explanations below
IFCExport(boost::python::list, std::string, std::string, bool, bool, bool, bool, bool, std::string, Point3D, double) -> void*

I FCExport( boost::python::list , std::string , std::string , bool , bool , bool , bool , bool , std::string , Point3D , double )

boost::python::list ( 1st argument ) in the C++ signature takes a list of member numbers. In the example , this list is given the variable name m_nums and is generated using the following lines of code:

# creates a list of member numbers for user-located members

mems = MultiMemberLocate("Locate members to export to IFC")
m_nums = []
for m in mems:                                                 # see iteration with a for loop
      m_nums .append( m.MemberNumber )

IFCExport( m_nums , obj.file_name, obj.path, obj.holes, obj.bolts, obj.welds,
False, False, "", Point3D(0.,0.,0.), 0.0 )

std::string ( 2nd argument ) is obj.file_name in the example. std::string ( 3nd argument ) is obj.path in the example . Both arguments take a string as their value. The user selects the file path and enters a file name in the dialog.

# code snippets related to creating a file name an file path

class DialogObject:
     file_name = "IFC_Test.ifc"                     # default file name
     path = "./output"                                       # default path

obj = DialogObject()
Dialog0 = Dialog( "IFC export" )
fs = ChooseFile( Dialog0, ' path ', label= "Select Directory")
Entry( Dialog0, ' file_name ', str )
Dialog0.model = [ obj ]
dd = Dialog0.done()

if os.path.isdir( obj.path ) == False:            # if the directory does not exist
     os.mkdir( obj.path )                                 # create a new directory

IFCExport( m_nums, obj .file_name , obj.path , obj.holes, obj.bolts, obj.welds,
False, False, "", Point3D(0.,0.,0.), 0.0 )

bool ( 4th argument ), bool ( 5th argument ), bool ( 6th argument ) correspond to obj.holes , obj.bolts , obj.weld in the example . All three arguments take True or False as their values. The user can choose, on the dialog, whether or not to show holes and/or bolts and/or welds in the IFC file that is output. Checked ( ) on the dialog corresponds to True. Not checked ( ) corresponds to False. The parametrically generated dialog mimics the functionality of the " Export holes " " Export bolts " and " Export welds " options on the IFC Properties window for Export Model. The example uses the following code:

# code snippets for letting user set, on a dialog, items to include

class DialogObject:
     holes = False                                       # default is no holes
     bolts = False                                        # default is no bolts
     welds = False                                      # default is no welds

obj = DialogObject()
Dialog0 = Dialog( "IFC export" )
Checkbox( Dialog0, ' holes ', "Export holes" )
Checkbox( Dialog0, 'bolts ', "Export bolts" )
Checkbox( Dialog0, ' welds ', "Export welds" )
Dialog0.model = [ obj ]
dd = Dialog0.done()

IFCExport( m_nums, obj.file_name, obj.path, obj.holes , obj .bolts , obj .welds ,
False, False, "", Point3D(0.,0.,0.), 0.0 )

bool ( 7th argument ) takes True or False as its value. Functionally, True is equivalent to checking the box for " Export Revit-compatible IFC files " on the IFC Properties window. The example shown near the top of this page sets this argument to False.

# code snippet that Revit compatibility to False

IFCExport( m_nums, obj.file_name, obj.path, obj.holes, obj.bolts, obj.welds,
                     False , False, "", Point3D(0.,0.,0.), 0.0 )

bool ( 8th argument ) takes True or False as its value. Functionally, True is equivalent to checking the box for " Export task scheduling info " on the IFC Properties window. The example shown near the top of this page sets this argument to False.

# code snippet that sets the export of task scheduling info to False

IFCExport( m_nums, obj.file_name, obj.path, obj.holes, obj.bolts, obj.welds,
                    False, False , "", Point3D(0.,0.,0.), 0.0 )

std::string ( 9th argument ) takes a string as its value. The string is the XML file name that is generated when the 8th argument (Export task scheduling info) is True. The example shown near the top of this page sets this argument to an empty string ("") since the 8th argument (in that example) is False.

# code snippet that sets the XML file name to an empty string

IFCExport( m_nums, obj.file_name, obj.path, obj.holes, obj.bolts, obj.welds,
                    False, False, "" , Point3D(0.,0.,0.), 0.0 )

Point3D ( 10th argument ) corresponds to Point3D(0.,0.,0.) in the example and is the global coordinate of the origin point in the IFC file. Point3D is a parametric module. This equates to the functionality of the " Origin translation " settings on the IFC Properties window for Export Model. The example uses the following code to define this point:

# code snippet for defining the IFC file's origin point

IFCExport( m_nums, obj.file_name, obj.path, obj.holes, obj.bolts, obj.welds,
False, False, "", Point3D(0.,0.,0.) , 0.0 )

double ( 11th argument ) corresponds to 0.0 in the example and is the number of degrees of rotation that you want applied to the IFC model. This value equates to the functionality of the value that is entered to the " Rotate CCW around Z axis " entry field on the IFC Properties window for Export Model. The example uses the following code to define this point:

# code snippet that specifies 0.0 degrees of rotation

IFCExport( m_nums, obj.file_name, obj.path, obj.holes, obj.bolts, obj.welds,
False, False, "", Point3D(0.,0.,0.), 0.0 )

page 1 | contents | modules | top