Add Shared Parameters

#📦 Variables
app = __revit__.Application #type: UIApplication
doc = __revit__.ActiveUIDocument.Document  #type: Document

#👉 Create Category Set 
cats = doc.Settings.Categories
cat_sheets = cats.get_Item(BuiltInCategory.OST_Sheets)
cat_views  = cats.get_Item(BuiltInCategory.OST_Views)

cat_set = app.Create.NewCategorySet()
cat_set.Insert(cat_sheets)
cat_set.Insert(cat_views)


#📁 Access shared parameter file
sp_file   = app.OpenSharedParameterFile()
sp_groups = sp_file.Groups


# 🔓 Start Transaction
t = Transaction(doc, 'Add Shared Parameters')
t.Start()

# Iterate through ParameterGroups and ParameterDefinitions
for d_group in sp_groups:
    for p_def in d_group.Definitions:
      
        #✅ Add Parameters with prefix 'PS_'    
        if 'PS_' in p_def.Name:
            print('Adding Parameter: {}'.format(p_def.Name))
            new_instance_binding = app.Create.NewInstanceBinding(cat_set)        
            doc.ParameterBindings.Insert( p_def, 
                                          new_instance_binding, 
                                          BuiltInParameterGroup.PG_TEXT)

t.Commit()#🔒 Commit Transaction

⌨️ Happy Coding!
Erik Frits