Ask Your Question
0

How to load a python script via batch file having a pss/e application running

asked 2018-03-14 12:15:03 -0500

john_smith gravatar image

updated 2018-03-14 12:15:52 -0500

Hi Folks,

I have a vba code that creates a batch file to open PSS/E and reads my python script. The batch file line that does that follows:

psse33 -pyfile "MyPythonScript.py"

So, I changed my vba code already to check if there is any PSS/E application running. But I don't know how to modify my batch file so it doesn't open a pss/e again if there is one launched. Instead, I'd like to simply activate the PSS/E window and load my python code. Does it make sense to you guys? I don't much about batch commands.

Please let me know if you have any idea. Thank you!

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2018-03-21 10:44:53 -0500

hunter2 gravatar image

If I'm understanding your question correctly, it sounds like you are trying to open an instance of PSSE and have that instance of PSSE execute a Python script. If an instance of PSSE is already open, then you want to control that instance and get it to execute your Python script. And this is all done by some vba code that creates a Windows batch file.

If that's correct, then your problem is with Windows process management. For security reasons, an operating system won't let one application's process directly interact with another application's process. On other words, you will need to open a new instance of PSSE every time. Windows will not let your vba script look for an open instance of PSSE and directly interact with it.

Elaborate more on what you are trying to accomplish with your vba scipt, and I might be able to help with a workaround.

edit flag offensive delete link more
0

answered 2018-03-21 12:35:42 -0500

jconto gravatar image

I agree with hunter2. Your vba script is creating a batch *.bat file to drive PSSe with a python script as argument. You can also call directly PSSe within the vba script. But you only have one opportunity to pass a script to PSSe. Once PSSe is running, it cannot be controlled from 'outside it.'

A workaround to execute multiple python scripts is to force PSSe to quit within the first python script and repeat the process of opening PSSe with a second script. Another workaround is let the batch file call PSSe with a 'master python script' that will 'execfile' multiple python scripts, each to perform different PSSe activities.

A better option (IMHO) is to drop vba for python to call PSSe's API functions, so PSSe is not running explicitly but through its API (see code for dyntools_demo.py in the EXAMPLE folder of the PTI installation - C:\Program Files (x86)\PTI\PSSE33\EXAMPLE) Now you can call as many python scripts as needed or implement their content as functions within this 'main' python code.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

2 followers

Stats

Asked: 2018-03-14 12:15:03 -0500

Seen: 1,431 times

Last updated: Mar 21 '18