I have altered your node to also accept an IFC config extracted from the current document with the help of @c.poupin 's post.
Perhaps you could absorb it into your version if you agree with the changes… I’ve added comments wherever i made changes.
It accepts an optional ifcExportConfig, if it’s provided, it will set all the options based on the config instead of the hard coded and optional user input.
#Based on a Nicklas Verdier Østergaard's script, nvo@niras.dk
#https://github.com/Autodesk/revit-ifc/tree/2810c479e27819da97656759a1dda28cbdde0538/Source
#Revised by Alban de Chasteigner
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
#REMARK: Added this function to find IFC versions instead of if checks
def get_ifc_version(version_str):
return {
"IFC4": IFCVersion.IFC4,
"IFC4RV": IFCVersion.IFC4RV,
"IFC4DTV": IFCVersion.IFC4DTV,
"IFC2x2": IFCVersion.IFC2x2,
"IFC2x3": IFCVersion.IFC2x3,
"IFC2x3CV2": IFCVersion.IFC2x3CV2,
"IFC2x3BFM": IFCVersion.IFC2x3BFM,
"IFC2x3FM": IFCVersion.IFC2x3FM,
"IFCBCA": IFCVersion.IFCBCA,
"IFCCOBIE": IFCVersion.IFCCOBIE,
"": IFCVersion.Default
}.get(version_str, IFCVersion.Default)
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
folder=UnwrapElement(IN[0])
view = tolist(UnwrapElement(IN[1]))
name=tolist(UnwrapElement(IN[2]))
fileversion = IN[3]
Projectorigin = IN[4]
inputPhase = UnwrapElement(IN[5])
userDefinedPset = IN[6]
revitInternalPset = IN[7]
wallandcolumnsplitting = IN[8]
exportbasequantities = IN[9]
config = IN[10]
test = ""
if inputPhase != None:
phaseString=str(inputPhase.Id)
else:
pass
if userDefinedPset != "":
userDefPsetBool= "true"
else:
userDefPsetBool= "false"
if revitInternalPset ==True:
revitInternalPset= "true"
else:
revitInternalPset= "false"
TransactionManager.Instance.EnsureInTransaction(doc)
result = []
for i,v in enumerate(view):
options=IFCExportOptions()
#REMARK: Added if check to pass this part if a config is provided.
if config == None:
#REMARK: Removed IF checks for IFC version and moved it to the get_ifc_version function
options.FileVersion = get_ifc_version(fileversion)
options.WallAndColumnSplitting = wallandcolumnsplitting
options.ExportBaseQuantities = exportbasequantities
options.FilterViewId = v.Id
options.AddOption("ExportInternalRevitPropertySets",revitInternalPset)
options.AddOption("ExportIFCCommonPropertySets","true")
options.AddOption("ExportAnnotations ","true")
options.AddOption("SpaceBoundaries ", "0")
options.AddOption("ExportRoomsInView", "false")
options.AddOption("Use2DRoomBoundaryForVolume ", "true")
options.AddOption("UseFamilyAndTypeNameForReference ", "true")
options.AddOption("Export2DElements", "false")
options.AddOption("ExportPartsAsBuildingElements", "false")
options.AddOption("ExportBoundingBox", "false")
options.AddOption("ExportSolidModelRep", "true")
options.AddOption("ExportSchedulesAsPsets", "false")
options.AddOption("ExportSpecificSchedules", "false")
#True doesn't work. It would be necessary to use OpenInBackground method.
options.AddOption("ExportLinkedFiles", "false")
options.AddOption("IncludeSiteElevation","true")
options.AddOption("StoreIFCGUID", "true")
options.AddOption("VisibleElementsOfCurrentView ", "true")
options.AddOption("UseActiveViewGeometry", "true")
options.AddOption("TessellationLevelOfDetail", "0,5")
options.AddOption("ExportUserDefinedPsets",userDefPsetBool)
if userDefinedPset != "":
options.AddOption("ExportUserDefinedPsetsFileName",userDefinedPset)
else:
pass
if inputPhase != None:
options.AddOption("ActivePhase", phaseString)
else:
pass
options.AddOption("SitePlacement", IN[4])
# options.AddOption("ClassificationName","x")
# options.AddOption("ClassificationFieldName","x")
#REMARK: Added this part. If config exists, we set all values based on the config. The standard options are set first, and then all additional options in the dict are added.
if config:
options.FilterViewId = v.Id
for key, value in config.items():
if key == "IFC_Version_str":
options.FileVersion = get_ifc_version(value)
elif key == "ExportBaseQuantities":
options.ExportBaseQuantities = value
elif key == "WallAndColumnSplitting":
options.WallAndColumnSplitting = value
else:
options.AddOption(key, str(value))
c=doc.Export(folder, name[i], options)
result.append(c)
# End Transaction
TransactionManager.Instance.TransactionTaskDone()
if fileversion == "":
OUT="Default settings used"
else:
OUT= "Success"
Perhaps you or @c.poupin could also create a custom node to get an IFC export setting by name, im currently just letting the user select the name and then use that key to get its values with data shapes which then get fed into the ifc export node.