How to get one of exisiting IFCExportConfiguration

Hi,
I’ve tried to search all over for how to get one of the existing IFC export options by ID, Name or by other means in python in Dynamo. As far as I can tell it is only possible through the external IFC export add-on and it’s dll’s. i know there is multiple packages providing this, but I want to see how it can be done through Python. Does any one have any guidance as to how to procede?

@jostein_olsen ,

i had similar issues

http://ifcopenshell.org/
you can find here stuff…

Thanks for the pointer, Andreas! However I don’t need access to the ifcopenshell lib, but rather a programmatic way to access the existing IFC configurations in a Revit document. I wasn’t quite sure whether or not it is possible and if so, how to proceed.

@jostein_olsen erfajo had some setting nodes, haven’t checked

Yep, I know. I just want to figure it out in Python. :slight_smile:

It’s possible. Not easy as the standard Revit API boilerplate templates won’t help as you need to step into DLLs usually not loaded, and the class names aren’t very intuitive… but certainly possible.

The Python code so you don’t have to retype it all from an image:


#Python environment setup
import clr #imports the common language runtime (CLR) and sys modules to the Python environment
clr.AddReference('C:\Program Files\Autodesk\Revit 2023\AddIns\IFCExporterUI\Autodesk.IFC.Export.UI.dll') #adds a reference to the DLL used for IFC exporter add-in to the CLR
import BIM.IFC.Export.UI as ifcX #loads the ifc exporter library into the python environment
#get the configuration mappings
desiredConfigName = IN[0] #the name of the export setting we want to use
ifcXConfigMap = ifcX.IFCExportConfigurationsMap() #creates a new (empty) ifc exporter configuraitons map object
ifcXConfigMap.AddSavedConfigurations() #adds the previously saved configurations to the configuratons map, including the default <In-Ssession Setup> configuration
ifcXConfigMap.AddBuiltInConfigurations() #adds the builtin configurations which ship with the add-in to the configurations map
#gets the saved configurations from the mapping
configurations = ifcXConfigMap.Values #gets the configurations as a "value collection" object, because of course this wouldn't be easy
enum = configurations.GetEnumerator() #gets the enumberator for the configuration value collection
selectedConfiguration = [] #sets an empty list for the selected configuration variable
#gets the selected configuration or the names of all available configurations
for i in range(configurations.Count): #for every item in the range of configurations perform the offset actions below
    enum.MoveNext() # move to the next item in the enumerations list; have to do this before we get the first item as the pointer will otherwise point at nothing
    now = enum.Current #gets the current enumeration
    selectedConfiguration.append(now.Name) #appends the name of the current enumeration to the selected configuration list
    if now.Name == desiredConfigName: #if the name matched the value given perform the offset lines below
        selectedConfiguration = now #set the selected configuraiton to the current item
        break #stop the for loop; no need to go further as we have the stuff we're after
#exits the python environment with a handy user message as the node warning so that if the item wasn't found we don't just pass null without explaining why
if selectedConfiguration.__class__ == [].__class__: #if the selectedConfiguration object is a list perform the offset lines below
    names = "\n\t• ".join(selectedConfiguration) #joins the available names into a sing string formattd as a bulletd list
    msg = "\n\nGiven Name Not in saved IFC Export Configurations. \nSelect one of the following:\n\t"+names #appends a handy message in front of the names list
    sys.exit(msg) #forces the python node into a warning state, setting the informational message as the output
#if the desired configuration was found, passes it the Dynamo environment
OUT = selectedConfiguration #passes the selected configuraiton (unless it was a list, as the sys.exit commmand would have prevented this line from executing) to the Dynamo environment

While this passes the selected configuration to the Dynamo environment, you might not want to do so. Personally I’d stay in the Python node and work with it there. The various options which you can set for the configuration can be found by probing the object with the dir function (OUT = dir(selectedConfiguration)).

3 Likes

Yeah right, that was easy… hehe :wink: Thank you so much, Jacob. A true forum hero!

1 Like