Get all categories MEP with corresponing IfcEntities, how?

Hello,

so my AI try does not work!

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import BuiltInCategory, Category, CategorySet
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

# Get all categories in the document
categories = doc.Settings.Categories

# Create a dictionary to store the IFC entities and their corresponding Revit categories
ifc_entities = {}

# Iterate through each category
for category in categories:
	if category.AllowsBoundParameters and category.CategoryType == CategoryType.Model:
		if category.HasMaterialQuantities:
			ifc_entity = category.get_Parameter(BuiltInParameter.IFC_ENTITY_LABEL).AsString()
			ifc_entities[ifc_entity] = category.Name

# Print the IFC entities and their corresponding Revit categories
output = {}

for ifc_entity, revit_category in ifc_entities.items():
	output.append(f'{ifc_entity}: {revit_category}')
	
OUT = output

there is still some trouble

background is i want to create a schedule for category! with 2 parameters (BuiltIn)
phase created and Family and Type
PyCreateSchedule.dyn (43.2 KB)

KR

Andreas

I don’t have time to dig into this today, but it would help if you also provided an IFC model to test in with some of your standard elements and known edge cases (if any).

you can grab MEP model from golden nugget f.e. @jacob.small , finally i need this schedules to implement in our office template…

or handout the script to planers.

also to have some kind dictionary {ifc:rft} would be great

KR

Andreas
MEP_Dataset_COMPLETE.rvt (6.2 MB)

…the buildinParameter i can`t get…

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#Preparing input from dynamo to revit
categories = doc.Settings.Categories


catname = []

for c in categories:
	catname.append(c.Name)


OUT = catname, categories

need i to import a library to load ? like IfcOpenShell

KR

Andreas

Just a note that these settings will vary from export to export as the mappings are customizable, so you can’t really rely on one dictionary forever. It’ll be a good base but it isn’t going to be static.

For a given category Revit you can pull in the IFC
Type with this method: GetIFCClassNameByCategory Method

Note this uses a new namespace so you will have to import that as well. Also unlikely that gpt will help here - Google will be your friend.

2 Likes

Hi,

for info, we can find a mapping IfcClass ⇔ Revit Categories into the Autodesk interoperability addin

3 Likes