Export a model using different sites

Hi @k.honda,

For starters, the code below is based on the “Export IFC” node of the Genius Loci package, so all credits go to @Alban_de_Chasteigner

If you enter the IFC export settings manually, you then also have the option to save these settings as a *.json file (as @Marcel_Rijsmus also indicates). If you open the exported json file in a text editor, you will get a good insight into all available export options (this differs per exporter and Revit version).

I took advantage of this by modifying Alban’s Python code. Now I need minimal input options, and all other options are fully customizable in the Python code itself. The code below is for Revit2019. I think you could add the option that Marcel mentions.

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]

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]))
Projectorigin = IN[3]


#### Start Transaction ####
TransactionManager.Instance.EnsureInTransaction(doc)
result = []

for i,v in enumerate(view):
	#### Define the export options ####
	options=IFCExportOptions()

	options.FilterViewId = v.Id
	options.AddOption("IsBuiltIn", "false")
	options.AddOption("IsInSession", "true")
	options.AddOption("Name", "<In-Session Setup>") # "Name"

	#### "General" Tab ####
	options.AddOption("IFCVersion", "21") # "IFC version"
	#  9 = IFC 2x2 Coordination View
	# 10 = IFC 2x3 Coordination View
	# 21 = IFC 2x3 Coordination View 2.0
	# 17 = IFC 2x3 GSA Concept Design BIM 2010
	# 27 = IFC 2x3 Basic FM Handover View
	# 24 = IFC 2x3 COBie 2.4 Design Deliverable View
	# 25 = IFC4 Reference View
	# 26 = IFC4 Design Transfer View 
	options.AddOption("ExchangeRequirement", "3") # "Exchange Requirement"
	#  0 = Architectural Reference Exchange
	#  1 = MEP Reference Exchange
	#  2 = Structural Reference Exchange
	#  3 = None
	options.AddOption("IFCFileType", "0") # "File type"
	#  0 = IFC
	#  1 = IFC XML
	#  2 = Zipped IFC
	#  3 = Zipped IFC XML
	options.AddOption("ActivePhaseId", "-1") # "Phase to export"
	# -1 = Default phase to Export
	options.AddOption("SpaceBoundaries", "0") # "Space boundaries"
	#  0 = None
	#  1 = 1st Level
	#  2 = 2nd Level
	options.AddOption("SitePlacement", IN[3]) # "Coordinate Base" --IN[4]--
	#  0 = Shared Coordinates
	#  1 = Survey Point
	#  2 = Project Base Point
	#  3 = Internal Origin
	# Set other export options
	options.AddOption("SplitWallsAndColumns", "false") # "Split Walls, Columns, Ducts by Level"
	options.AddOption("IncludeSteelElements", "true") # "Include Steel Elements"
	
	#### "Additional Content" Tab ####
	options.AddOption("Export2DElements", "false")
	options.AddOption("ExportLinkedFiles", "false") 
	options.AddOption("VisibleElementsOfCurrentView", "true")
	options.AddOption("ExportRoomsInView", "false")   

	#### "Property Sets" Tab ####
	options.AddOption("ExportInternalRevitPropertySets", "false")
	options.AddOption("ExportIFCCommonPropertySets","true")
	options.AddOption("ExportBaseQuantities", "false")
	options.AddOption("ExportSchedulesAsPsets", "false")
	options.AddOption("ExportSpecificSchedules", "false") 
	options.AddOption("ExportUserDefinedPsets", "true")
	options.AddOption("ExportUserDefinedPsetsFileName", "G:\\data\\User Defined Property Sets.txt")
	options.AddOption("ExportUserDefinedParameterMapping", "true")
	options.AddOption("ExportUserDefinedParameterMappingFileName", "G:\\data\\Parameter Mapping Table.txt")

	#### "Level of Detail" Tab ####
	options.AddOption("TessellationLevelOfDetail", "0,5")

	#### "Advanced" Tab ####
	options.AddOption("ExportPartsAsBuildingElements", "false")
	options.AddOption("ExportSolidModelRep", "true")
	options.AddOption("UseActiveViewGeometry", "true")
	options.AddOption("UseFamilyAndTypeNameForReference", "false")
	options.AddOption("Use2DRoomBoundaryForVolume", "false")
	options.AddOption("IncludeSiteElevation","false")
	options.AddOption("StoreIFCGUID", "true")
	options.AddOption("ExportBoundingBox", "false")
	options.AddOption("UseOnlyTriangulation", "false")
	options.AddOption("UseTypeNameOnlyForIfcType", "false")
	options.AddOption("UseVisibleRevitNameAsEntityName", "false")
	#options.AddOption("ExportAnnotations ","true")

	c=doc.Export(folder, name[i], options)
	result.append(c)

#### End Transaction ####
TransactionManager.Instance.TransactionTaskDone()

OUT='Success'

4 Likes