# Buggy code
def get_elements_by_categories(element_bicats, elements=None, doc=None):
    # if source elements is provided
    if elements:
        return [
            x
            for x in elements
            if get_builtincategory(x.Category.Name) in element_bicats
        ]

    # otherwise collect from model
    cat_filters = [DB.ElementCategoryFilter(x) for x in element_bicats]
    elcats_filter = DB.LogicalOrFilter(framework.List[DB.ElementFilter](cat_filters))
    return (
        DB.FilteredElementCollector(doc or HOST_APP.doc)
        .WherePasses(elcats_filter)
        .WhereElementIsNotElementType()
        .ToElements()
    )


# Traceback (Exception)
ERROR [pyrevit.revit.db.transaction] Error in TransactionGroup Context. Rolling back changes. | <type 'exceptions.Exception'>:The input argument "categoryId" of function `anonymous-namespace'::ElementCategoryFilter_constructor or one item in the collection is null at line 230 of file d:\ship\2019_px64\source\revit\revitdbapi\gensrc\APIBuiltInElementFiltersProxy.cpp.
Parameter name: categoryId

IronPython Traceback:
Traceback (most recent call last):
File "C:\Users\jriga\AppData\Roaming\pyRevit-Master\extensions\pyRevitTools.extension\pyRevit.tab\Modify.panel\edit2.stack\ReNumber.pushbutton\script.py", line 307, in <module>
File "C:\Users\jriga\AppData\Roaming\pyRevit-Master\extensions\pyRevitTools.extension\pyRevit.tab\Modify.panel\edit2.stack\ReNumber.pushbutton\script.py", line 191, in pick_and_renumber
File "C:\Users\jriga\AppData\Roaming\pyRevit-Master\extensions\pyRevitTools.extension\pyRevit.tab\Modify.panel\edit2.stack\ReNumber.pushbutton\script.py", line 122, in get_elements_dict
File "C:\Users\jriga\AppData\Roaming\pyRevit-Master\pyrevitlib\pyrevit\revit\db\query.py", line 261, in get_elements_by_categories
Exception: The input argument "categoryId" of function `anonymous-namespace'::ElementCategoryFilter_constructor or one item in the collection is null at line 230 of file d:\ship\2019_px64\source\revit\revitdbapi\gensrc\APIBuiltInElementFiltersProxy.cpp.
Parameter name: categoryId


Script Executor Traceback:
Autodesk.Revit.Exceptions.ArgumentNullException: The input argument "categoryId" of function `anonymous-namespace'::ElementCategoryFilter_constructor or one item in the collection is null at line 230 of file d:\ship\2019_px64\source\revit\revitdbapi\gensrc\APIBuiltInElementFiltersProxy.cpp.
Parameter name: categoryId
à Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
à Microsoft.Scripting.Interpreter.Interpreter.HandleException(InterpretedFrame frame, Exception exception)
à Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
à Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
à IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
à PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime&amp; runtime)

# Fixed code
def get_elements_by_categories(element_bicats, elements=None, doc=None):
    # if source elements is provided
    if elements:
        return [
            x
            for x in elements
            if get_builtincategory(x.Category.Name) in element_bicats
        ]

    # otherwise collect from model
    cat_filters = [DB.ElementCategoryFilter(x) for x in element_bicats if x]
    elcats_filter = DB.LogicalOrFilter(framework.List[DB.ElementFilter](cat_filters))
    return (
        DB.FilteredElementCollector(doc or HOST_APP.doc)
        .WherePasses(elcats_filter)
        .WhereElementIsNotElementType()
        .ToElements()
    )