Question about setting 'Apparent load calculation method' with Python

Hello All,

I have a question about setting ‘Apparent load calculation method’ with Python. The CircuitLoadCalculationMethod property in ElectricalSetting class has two values:

CircuitLoadCalculationMethod Property:
http://www.revitapidocs.com/2017.1/2554ffbc-6e19-677a-cd3a-a267d2664d10.htm

CircuitLoadCalculationMethod Enumeration:
http://www.revitapidocs.com/2017.1/d3ce255f-f1a1-7b52-a48c-320314213632.htm

In my code I have this:

s1 = CircuitLoadCalculationMethod.SumTrueLoadAndReactiveLoad // This returns ‘SumTrueLoadAndReactiveLoad’
s2 = CircuitLoadCalculationMethod.SumApparentLoad // This returns ‘SumApparentLoad’

i1 = int(CircuitLoadCalculationMethod.SumTrueLoadAndReactiveLoad) // This returns ‘0’
i2 = int(CircuitLoadCalculationMethod.SumApparentLoad) // This returns ‘1’

With the above, I think I am getting one step closer if I can set CircuitLoadCalculationMethod to ‘i1’ or ‘i2’ (or maybe ‘0’ or ‘1’). When I do this in Python:

ElectricalSetting.CircuitLoadCalculationMethod.Set(i2) // This return an error: AttributeError: ‘getset_descriptor’ object has no attribute ‘Set’

ElectricalSetting.CircuitLoadCalculationMethod.Get() // This return an error: AttributeError: ‘getset_descriptor’ object has no attribute ‘Get’

Okay, then I tried:

ElectricalSetting.CircuitLoadCalculationMethod.SetValue(1) // TypeError: SetValue() takes exactly 2 arguments (1 given)

I am not sure what the second arguments it is looking for. I surely don’t know how to SetValue a enum. Appreciate your help on this!

It is expecting the following two arguments:
-ElectricalSetting (of your document)
-CircuitLoadCalculationMethod (which will be the new value)

import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Electrical import *

doc = DocumentManager.Instance.CurrentDBDocument
settings = doc.Settings.ElectricalSetting
settings_method = settings.CircuitLoadCalculationMethod

load_true = CircuitLoadCalculationMethod.SumTrueLoadAndReactiveLoad
load_apparent = CircuitLoadCalculationMethod.SumApparentLoad

TransactionManager.Instance.EnsureInTransaction(doc) # Begin Revit document transaction
ElectricalSetting.CircuitLoadCalculationMethod.SetValue(settings, load_apparent)
TransactionManager.Instance.TransactionTaskDone() # End Revit document transaction

A bit of an explanation of what’s happening here…

i1 = int(CircuitLoadCalculationMethod.SumTrueLoadAndReactiveLoad) // This returns ‘0’
i2 = int(CircuitLoadCalculationMethod.SumApparentLoad) // This returns ‘1’

In your above lines, casting these CircuitLoadCalculationMethod members to integers will return their respective values. Even if you passed the document as the first argument and 1 as the second, it would raise the following error:

image

Rather than setting the CircuitLoadCalculationMethod to an integer, you have to set it to an actual CircuitLoadCalculationMethod.

1 Like

Hi Christian,

Thank you for your detail explanation. Your suggested solution works perfectly in my case. Appreciate you big help on this. You really saved my day!

Kevin

1 Like