ChangeParametersMultipleElement Sample Code: Python
#The following example uses Python 3.x syntax
#Python with COM requires the pyWin32 extensions
import win32com.client
from win32com.client import VARIANT
# This will import VT_VARIANT
import pythoncom
# This will establish the connection
object = win32com.client.Dispatch("pwrworld.SimulatorAuto")
# The following function will determine if any errors are returned and print an appropriate message.
def CheckResultForError(SimAutoOutput, Message):
if SimAutoOutput[0] != '':
print ('Error: ' + SimAutoOutput[0])
else:
print (Message)
filename = "C:\TestCode\B7FLAT.pwb"
CheckResultForError(object.OpenCase(filename), 'Case open')
ObjectType = "GEN"
#VARIANT is needed if passing in array of arrays. BOTH the field list
#and the value list must use this syntax. If not passing in arrays of arrays, the
#standard list format can be used. Passing out arrays of arrays from SimAuto in the
#output parameter seems to work OK with Python.
FieldArray = VARIANT(pythoncom.VT_VARIANT | pythoncom.VT_ARRAY, ["BusNum", "ID", "MW", "AGC"])
AllValueArray = [None]*2
AllValueArray[0] = VARIANT(pythoncom.VT_VARIANT | pythoncom.VT_ARRAY, [1, "1", 300, "NO"])
AllValueArray[1] = VARIANT(pythoncom.VT_VARIANT | pythoncom.VT_ARRAY, [2, "1", 1400, "NO"])
CheckResultForError(object.ChangeParametersMultipleElement("GEN", FieldArray, AllValueArray), 'Do change')
filename = "C:\TestCode\B7FLAT_changed.pwb"
CheckResultForError(object.SaveCase(filename,"PWB", True), 'Save case')
#This will close the connection
del object
object = None