GetParamsTypedCols 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.GetParamsTypedCols("GEN", FieldArray, "", pythoncom.VT_R8)

CheckResultForError(output, 'Get Typed All Same')

# Results in error Unsupported conversion of non-scalar field ID to VT_R8.

# Would also result in error for field AreaName if ID field is removed.

 

# The following will return results without an error because appropriate type for each field is specified.

FieldArray = ["BusNum", "ID", "GenMW", "AreaName"]

ColTypesArray = [pythoncom.VT_I4, pythoncom.VT_BSTR, pythoncom.VT_R8, pythoncom.VT_BSTR]

output = object.GetParamsTypedCols("GEN", FieldArray, "", ColTypesArray)

CheckResultForError(output, 'Get Typed Each Specified')

 

# Filter is written as a single-condition filter that returns the generators at Bus 1.

FieldArray = ["BusNum", "ID", "GenMW", "AreaName"]

ColTypesArray = [pythoncom.VT_I4, pythoncom.VT_BSTR, pythoncom.VT_R8, pythoncom.VT_BSTR]

output = object.GetParamsTypedCols("GEN", FieldArray, "BusNum = 1", ColTypesArray)

CheckResultForError(output, 'Get Typed Using Single-condition Filter')

 

# The following will NOT result in an error because results are returned as variants.

FieldArray = ["BusNum", "ID", "GenMW", "AreaName"]

output = object.GetParamsTypedCols("GEN", FieldArray, "", pythoncom.VT_VARIANT)

CheckResultForError(output, 'Get Typed Using VT_VARIANT')

 

 

#This will close the connection

del object

object = None