How can I use subscripts in ComPython object?

Category:
Scripting
Answer

ComPython has a different approach to subscripting as compared to ComDPL. Two methods are shown below:

  1. Define a subfunction inside your *.py file. This subfunction can later on be used at any place of your *.py file. It is only important that the subfunction is properly defined and properly called. To do this refer to the Python literature. Below, a small example is provided:

 import powerfactory

app=powerfactory.GetApplication()

 def subfunction():               # definition of subfunction with def nameOfTheSubfunction

   app.PrintPlain('This text comes from a subfunction')           #what the subfunction does

subfunction()                   # calling later the subfunction

 

      2. Define a module that contains code of your subscript and import it in the corresponding *.py file.

Example:

  • *.py file

import powerfactory

app=powerfactory.GetApplication()

import sys                                         #importing sys module

sys.path.append(r'C:\Users\....\Desktop')     #appending path where module is saved

import moduleSubRoutine                           #importing module

moduleSubRoutine.Function1(app)                    #calling functions defined in module

  •  moduleSubRoutine

def Function1(app):

   app.PrintPlain('Contents of the subscript code')

Back