Add Shared Parameters from txt File Error

Hi everyone,
I am trying to load shared parameter to the project and then bind them to the categories

# Import the required Revit API classes
import clr
clr.AddReference('RevitAPI')
import Autodesk.Revit.DB as DB

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

# Set the path to the shared parameters file
sharedParametersFile = IN[0]

# Load the shared parameters file
defFile = DB.ExternalFileUtils.ToString(sharedParametersFile)
categorySet = DB.ElementIdSet()
categorySet.Insert(DB.ElementId(DB.BuiltInCategory.OST_Walls))

# Create a category set and a definition map
categorySet = DB.ElementIdSet()
categorySet.Insert(DB.ElementId(DB.BuiltInCategory.OST_Walls))
defMap = DB.DefinitionBindingMap()

# Add the shared parameters to the definition map
for defGroup in defFile:
    for definition in defGroup.Definitions:
        if definition.Name not in defMap:
            defMap.Add(definition, categorySet)

# Bind the shared parameters to the categories
doc = Revit.ActiveUIDocument.Document
transaction = DB.Transaction(doc, "Bind Shared Parameters")
transaction.Start()
DB.ParameterBindingService.GetBindingOptions(doc)
DB.ParameterBindingService.OverrideBinding(doc, defMap, DB.BindingPriorityType.Temporary)
transaction.Commit()

Something doesnt seem to work. Could someone help me understand where might be going wrong about the steps.
QIC_Shared_Parameter_File.txt (1.2 KB)
001_PythonBatchProcessing_Parameters.dyn (6.6 KB)

Your code?
There are a bunch of issues.
First you need imports. You can’t declare DB unless you have DB.

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

Further, it looks like you want to work with system collections. Need to import those first.

from System.Collections.Generic import

Next, your declaration of a collection isn’t quite right. There is no thing called an ElementIdSet. You can make a Element set. Or you can make an ElementId set. Really those are iList collections.

categoryIdcolelction = List[ElementId]()
elementcollection = List[Element]()

Then to add to the List (these are .Net Colelctions - not python lists…), just use elementcollection.Add(eleement), rather than elementcollection.Insert(element)

There is a ElementSet class in DB. Are you trying to use that?

categorySet = DB.ElementSet()

But I’m not sure that is what you want. ElementSet is usually used for a document selection or FiltereElementCollection and can contain elements of different types. Here you are after a strongly typed list. But ElementSet would tie in with your Insert() method as that is indeed a method of ElementSet…

I hope that gets you pointed in the right direction. Not sure how you derived the above code unless you were just copy/pasting stuff(?)