GetParamsRectTyped Sample Code: Python
#The following example uses Python 3.x syntax
#Python with COM requires the pyWin32 extensions
import win32com.client
# 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 = "B7FLAT.pwb"
CheckResultForError(object.OpenCase(filename), 'Case open')
# The following will result in an error because ID and AreaName are strings that cannot be converted to a floating point number.
FieldArray = ["BusNum", "ID", "GenMW", "AreaName"]
output = object.GetParamsRectTyped("GEN", FieldArray, "", pythoncom.VT_R8)
CheckResultForError(output, 'Get Typed')
# Results in error Unsupported conversion of non-scalar field ID to a non-VT_BSTR type.
# Would also result in error for field AreaName if ID field is removed.
# The following will NOT result in an error because results are returned as variants.
FieldArray = ["BusNum", "ID", "GenMW", "AreaName"]
output = object.GetParamsRectTyped("GEN", FieldArray, "", pythoncom.VT_VARIANT)
CheckResultForError(output, 'Get Typed')
# The following will return results without an error because both fields can be converted to floating point values.
# Filter is written as a single-condition filter that returns the generators at Bus 1.
FieldArray = ["BusNum", "GenMW"]
output = object.GetParamsRectTyped("GEN", FieldArray, "BusNum = 1", pythoncom.VT_R8)
CheckResultForError(output, 'Get Typed')
#This will close the connection
del object
object = None