I’m having trouble using an excel file to take the name of shared parameters in it, with their settings; and load it into the project. I’m using some Python 3 code here:
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Function to add shared parameters
def add_shared_parameters(param_data, shared_params):
app = doc.Application
shared_params_file = app.OpenSharedParameterFile()
if shared_params_file is None:
raise Exception("Shared parameters file not found.")
for i, param in enumerate(param_data):
try:
param_group = param{0]
param_type = param[1]
param_group = param[2]
bip_name = param[3]
is_instance = param[4]
param_name = param[5]
# Find the shared parameter in the shared parameters file
for group in shared_params_file.Groups:
if group.Name == param_group:
for definition in group.Definitions:
if definition.Name == param_name:
# Create the shared parameter
TransactionManager.Instance.EnsureInTransaction(doc)
new_param = doc.FamilyManager.AddParameter(definition, BuiltInParameterGroup.PG_DATA, is_instance)
TransactionManager.Instance.TransactionTaskDone()
break
except IndexError:
print(f"IndexError: Check the data at index {i} in param_data or shared_params.")
# Example usage
param_data = IN[5] # Connect the Excel data to this input
shared_params = IN[6] # Connect the filtered shared parameters to this input
# Ensure that the length of param_data and shared_params are consistent
if len(param_data) != len(shared_params):
raise Exception("The length of param_data and shared_params must be the same.")
add_shared_parameters(param_data, shared_params)
And the sample excel list is formatted as so:
Column 1 | Column 2 | Column 3 | Column 4 | E | F |
---|---|---|---|---|---|
Shared Parameter Name | Shared Parameter Group | Parameter Type | Parameter Group | BIP Name | Instance |