Ask Your Question

Revision history [back]

Take a look at the answer to this post: https://psspy.org/psse-help-forum/question/656/accessing-model-index-values-eg-var-nums-from-python/


After seeing what you actually want to do, try something similar to the following:

#THIS CODE WILL SET THE CON(J+5) TO 0.0 IF THE VALUE OF THAT CON IS GREATER THAN 0.0
#   FOR ALL GENROU MODELS IN THE CASE

#MODIFY BSYS TO A DEFINED SUBSYSTEM IF YOU DON'T WANT TO RUN ON ENTIRE CASE
BSYS = -1
ierr, buses = psspy.amachint(BSYS,4,'NUMBER')
ierr, ids = psspy.amachchar(BSYS,4,'ID')
for i in range(len(buses[0])):
    ierr, model_name = psspy.mdlnam(buses[0][i],ids[0][i],'GEN')
    if ierr:
        continue
    #CHANGE 'GENROU' TO WHATEVER MODEL YOU ARE LOOKING FOR
    if 'GENROU' in model_name:
        ierr, con_index = psspy.mdlind(buses[0][i], ids[0][i], 'GEN', 'CON')
        ierr, con_num = psspy.mdlind(buses[0][i], ids[0][i], 'GEN', 'NCON')
        cons = []
        for i in range(con_num - 1):
            ierr, con_val = psspy.dsrval('CON', con_index + i)
            cons.append([con_index + i, con_val])

        #NOT REALLY SURE WHERE YOU ARE GOING TO TAKE THIS, BUT YOU COULD DO SOMETHING LIKE THIS:
        if cons[5][1] > 0:
            NEW_VAL = 0.0
            psspy.change_con(cons[5][0],NEW_VAL)

I have no idea what you are planning on doing with this, but hopefully this code will help out a bit. I found the 'dsrval' command in the API, so parsing wasn't necessary. to change the con, use the 'change_con' command.