Def func is not work

this work to get builtIn Category

but why its not work in def function ?

import clr, System
clr.AddReference("RevitNodes")
import Revit
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
 
def get_bic(catname) :

	ost=[]	
	bic = System.Enum.GetValues(BuiltInCategory) 
	cats, bics = [], []
	for i in bic:
    	try:
    	    cat = Revit.Elements.Category.ById(ElementId(i).IntegerValue)
    	    cats.append(cat)
    	    bics.append(i)
    	except:
    	    pass
 
	for i, b in zip(cats, bics):
    	if catname == str(i): 
    	    ost = b 
    return ost

OUT =get_bic(IN[0])

Try getting rid of the empty line after def get_bic(catname) : and avoid mixing tabs and spaces in your indentations.

1 Like

@Dimitar_Venkov , thanks for answer but i try its (( but its no work …

only with extra def its work (im dont why… must be more simpe solution… ) :

import clr, System
clr.AddReference("RevitNodes")
import Revit
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *


def try_except_cats(x):
	
   	try:
   		cat = Revit.Elements.Category.ById(ElementId(x).IntegerValue).ToString()	
   	except:
		cat=None #"INVALID or another without BuiltInCategory element " 
	return cat
	
	
def get_cats(catname):
	
	bics_names=[[i, try_except_cats(i)] for i in System.Enum.GetValues(BuiltInCategory)]
 	bics=[i[0] for i in bics_names]
 	names=[i[1] for i in bics_names]
	ost=[i for i, b in zip(names, bics) if catname == str(b)]    	    
	return  ost[0] 

 
OUT = get_cats(IN[0])

It’s clearly indentations as error says…

2 Likes

@Tomasz_Puchala
But its my code…its work to you ? if yes , please copy-paste there…

I can also confirm, works as supposed to, when fixed tab and spaces…

import clr, System
clr.AddReference('RevitNodes')
import Revit
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
 
def get_bic(catname):
    ost=[]
    bic = System.Enum.GetValues(BuiltInCategory)
    cats, bics = [], []
    for i in bic:
        try:
            cat = Revit.Elements.Category.ById(ElementId(i).IntegerValue)
            cats.append(cat)
            bics.append(i)
        except:
            pass
    for i, b in zip(cats, bics):
        if catname == str(i):
            ost = b
    return ost

OUT = get_bic(IN[0])
3 Likes

Great , its time to copy-paste for me )
Its Works !
@Dimitar_Venkov
@Tomasz_Puchala
@erfajo

2 Likes