Set Electrical Load Classification Demand Factor using Dynamo

I am having trouble setting the Load Classification property of DemandFactorId in python.

# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
#import Revit
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Electrical import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc =  DocumentManager.Instance.CurrentDBDocument

# The inputs to this node will be stored as a list in the IN variables.
type_of_building = IN[0][0][0]
load_classification = IN[1]
demand_factors = IN[2]
parent_list = []
app_list = []
app_list.append("Old Demand Factor --> New Demand Factor")

def get_demand(name):
	rtn_val = "NULL"
	for demand_factor in demand_factors:
		unwrap = UnwrapElement(demand_factor)
		u_name = unwrap.Name
		if u_name == name:
			rtn_val = demand_factor
	if rtn_val == "NULL":
		for temp in demand_factors:
			if temp.Name == "Default":
				rtn_val = temp
		
	return rtn_val
	
for item in load_classification:
	try:
		unwrapped = UnwrapElement(item)
		# Get Demand Factor ID
		# Load Classification ID
		ele_name = unwrapped.Name
		ele_demand_id = unwrapped.DemandFactorId
		demand = get_demand(ele_name)
		u_demand = UnwrapElement(demand)
		demand_factor_id = u_demand.Id
		if ele_demand_id != demand_factor_id:

WHAT TO DO NOW?  Been trying lots of things, and it isn't working to set the demand factor on the load class.
			
	except:
		app_list.append("Error: " + str(ele_name))

# Place your code below this line

# Assign your output to the OUT variable.
OUT = app_list

The reason we are attempting this is because we have a Revit template that gets built up additively. We wanted to add to the setup routines a choice to select a building type (Hospital, Hotel…) and assign the Demand Factors that change per building type.

@Mostafa_El_Ayoubi I saw that Mostafa has been first to chime in on things like this for other property trouble so I thought I’d see if he has seen this before.

Woohoo. We got it working. It helps to try and change the unwrapped item and using the transaction manager.
2021-08-04 09_55_07-Set Demand Factors

Shout out to Jack Haek our coding intern for getting this to work.

Now whether or not this is a good way to handle the issue we will be discussing later today with the electrical engineers.