susantoj / powerfactory_python

Python scripting for PowerFactory
GNU General Public License v2.0
35 stars 17 forks source link

EXECUTION OF .py FILES #2

Open Johnaristidou opened 4 years ago

Johnaristidou commented 4 years ago

Hello,

I am working on a project using digsilent and python like your project.

I just want to know how you execute these python files.

Do you execute them externally through digsilent or directly from pycharm or anaconda?

To be more specific,because I am a beginner on working with digsilent, I want to execute a python file using powerfactory module directly from pycharm. If I execute my script externally or embed my code in digsilent I get results. But if I execute the script from pycharm I have to face problems with powerfactory module. This issue does not have to do with python version which I use

Is it possible to execute a script directly through pycharm?

Looking forward to your reply John

peace899 commented 4 years ago

The examples in this repo are run inside PowerFactory itself. To execute extrenally you have to load the powerfactory module in pycharm like so: import sys sys.path.append(r'C:\Program Files\DIgSILENT\PowerFactory 2018 SP3\Python\3.6') import powerfactory as pf

Johnaristidou commented 4 years ago

I have tried this with the hello world example as it is given from tutorial with no result.It understands GetApplication function but no any other method

It gives me an error on PrintPlain function.

To be more specific I want output results from a script to be printed on pycharm console.

Is this possible? Looking forward for your reply John

peace899 commented 4 years ago

Can you show your code?

Johnaristidou commented 4 years ago

Ok I will show you 2 photos using the LineLength script from the tutorial.

The first one is from execution on pycharm where you can see that it gives me error.

The second one is from powerfactory where the script executed succesfully counting the length of lines from my project

I want those results to be printed on pycharm for further calculations

[Image]

[Image]

Get Outlook for Androidhttps://aka.ms/ghei36


From: Peace L notifications@github.com Sent: Sunday, September 15, 2019 9:17:14 PM To: susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Ioannis Aristidou aristidou.ioannis@ucy.ac.cy; Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Can you show your code?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/susantoj/powerfactory_python/issues/2?email_source=notifications&email_token=ANFZYWDY4LOAR63ZDD6QBHDQJZ32VA5CNFSM4IWQZN72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XWDLA#issuecomment-531587500, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANFZYWD7NXQA4ON2NFH5LZTQJZ32VANCNFSM4IWQZN7Q.

Johnaristidou commented 4 years ago

Note that I executed this script externally in powerfactory not internally.I saved the script in powerfactory folder which is the external directory and I loaded it

Get Outlook for Androidhttps://aka.ms/ghei36


From: Ioannis Aristidou Sent: Sunday, September 15, 2019 9:32:20 PM To: susantoj/powerfactory_python reply@reply.github.com; susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Ok I will show you 2 photos using the LineLength script from the tutorial.

The first one is from execution on pycharm where you can see that it gives me error.

The second one is from powerfactory where the script executed succesfully counting the length of lines from my project

I want those results to be printed on pycharm for further calculations

[Image]

[Image]

Get Outlook for Androidhttps://aka.ms/ghei36


From: Peace L notifications@github.com Sent: Sunday, September 15, 2019 9:17:14 PM To: susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Ioannis Aristidou aristidou.ioannis@ucy.ac.cy; Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Can you show your code?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/susantoj/powerfactory_python/issues/2?email_source=notifications&email_token=ANFZYWDY4LOAR63ZDD6QBHDQJZ32VA5CNFSM4IWQZN72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XWDLA#issuecomment-531587500, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANFZYWD7NXQA4ON2NFH5LZTQJZ32VANCNFSM4IWQZN7Q.

peace899 commented 4 years ago

Unfortunately cannot see the images..

Johnaristidou commented 4 years ago

[Image]

[Image]

Get Outlook for Androidhttps://aka.ms/ghei36


From: Peace L notifications@github.com Sent: Sunday, September 15, 2019 10:06:19 PM To: susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Ioannis Aristidou aristidou.ioannis@ucy.ac.cy; Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Unfortunately cannot see the images..

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/susantoj/powerfactory_python/issues/2?email_source=notifications&email_token=ANFZYWDIXGRONL2CIKHNBWLQJ2BSXA5CNFSM4IWQZN72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XW6GA#issuecomment-531590936, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANFZYWG52FXXLQN2BRPTUNDQJ2BSXANCNFSM4IWQZN7Q.

Johnaristidou commented 4 years ago

What about now? Is it ok? Get Outlook for Androidhttps://aka.ms/ghei36


From: Ioannis Aristidou Sent: Sunday, September 15, 2019 10:28:57 PM To: susantoj/powerfactory_python reply@reply.github.com; susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

[Image]

[Image]

Get Outlook for Androidhttps://aka.ms/ghei36


From: Peace L notifications@github.com Sent: Sunday, September 15, 2019 10:06:19 PM To: susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Ioannis Aristidou aristidou.ioannis@ucy.ac.cy; Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Unfortunately cannot see the images..

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/susantoj/powerfactory_python/issues/2?email_source=notifications&email_token=ANFZYWDIXGRONL2CIKHNBWLQJ2BSXA5CNFSM4IWQZN72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XW6GA#issuecomment-531590936, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANFZYWG52FXXLQN2BRPTUNDQJ2BSXANCNFSM4IWQZN7Q.

Johnaristidou commented 4 years ago

The white one is from execution in powerfactory the other two is the code and its output on pycharm.

I hope now it will be more clearly to see them

[Image]

[Image]

[Image]

Get Outlook for Androidhttps://aka.ms/ghei36


From: Ioannis Aristidou Sent: Sunday, September 15, 2019 10:28:57 PM To: susantoj/powerfactory_python reply@reply.github.com; susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

[Image]

[Image]

Get Outlook for Androidhttps://aka.ms/ghei36


From: Peace L notifications@github.com Sent: Sunday, September 15, 2019 10:06:19 PM To: susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Ioannis Aristidou aristidou.ioannis@ucy.ac.cy; Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Unfortunately cannot see the images..

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/susantoj/powerfactory_python/issues/2?email_source=notifications&email_token=ANFZYWDIXGRONL2CIKHNBWLQJ2BSXA5CNFSM4IWQZN72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XW6GA#issuecomment-531590936, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANFZYWG52FXXLQN2BRPTUNDQJ2BSXANCNFSM4IWQZN7Q.

peace899 commented 4 years ago

Still cant see, can you copy and paste your code here

Johnaristidou commented 4 years ago

Here is the code import sys sys.path.append(r'C:\Program Files\DIgSILENT\PowerFactory 2019 SP1\Python\3.7')

import powerfactory app = powerfactory.GetApplication() lines = app.GetCalcRelevantObjects("*.ElmLne") length = 0 linesNr = len(lines) for line in lines: length += line.dline

option 1 (simpler and intoduce GetAttributeUnit in the second part of the exercise)

app.PrintPlain("Total length of the %i" %(linesNr) + " lines is: %.2f " %(length) + "km")

option 2

unit = line.GetAttributeUnit('dline') app.PrintPlain("Total length of the %i" %(linesNr) + " lines is: %.2f " %(length) + unit)

Here is the error message that I get from pycharm

Traceback (most recent call last): File "C:/Users/CS8675/PycharmProjects/DIGSILENT/test.py", line 6, in lines = app.GetCalcRelevantObjects("*.ElmLne") AttributeError: 'NoneType' object has no attribute 'GetCalcRelevantObjects'

Here is the output when I executed externally from powerfactory

info - Python Script 'Python Script(5)' started Total length of the 45 lines is: 26572.00 km Total length of the 45 lines is: 26572.00 m info - Python Script 'Python Script(5)' successfully executed

Results are taken from a project inside powerfactory


From: Peace L notifications@github.com Sent: 15 September 2019 13:02 To: susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Ioannis Aristidou aristidou.ioannis@ucy.ac.cy; Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Still cant see, can you copy and paste your code here

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/susantoj/powerfactory_python/issues/2?email_source=notifications&email_token=ANFZYWFHE425OWC2U3ZJBY3QJ2IF7A5CNFSM4IWQZN72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XX43Q#issuecomment-531594862, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANFZYWHKR7DOPRMYBFOP4ILQJ2IF7ANCNFSM4IWQZN7Q.

peace899 commented 4 years ago

Traceback (most recent call last): File "C:/Users/CS8675/PycharmProjects/DIGSILENT/test.py", line 6, in <module> lines = app.GetCalcRelevantObjects("*.ElmLne") AttributeError: 'NoneType' object has no attribute 'GetCalcRelevantObjects'

It means your 'app' instance does not have an active object which has GetCalcRelevantObjects', from your posted code it means you don't have an active project. You didn't activate your project.

Johnaristidou commented 4 years ago

I activated it and then I executed my code in pycharm.I also tested helloworld.py script where is just a printing but it executed only in powerfactory

Get Outlook for Androidhttps://aka.ms/ghei36


From: Peace L notifications@github.com Sent: Monday, September 16, 2019 12:43:53 PM To: susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Ioannis Aristidou aristidou.ioannis@ucy.ac.cy; Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Traceback (most recent call last): File "C:/Users/CS8675/PycharmProjects/DIGSILENT/test.py", line 6, in lines = app.GetCalcRelevantObjects("*.ElmLne") AttributeError: 'NoneType' object has no attribute 'GetCalcRelevantObjects'

It means your 'app' instance does not have an active object which has GetCalcRelevantObjects', from your posted code it means you don't have an active project. You didn't activate your project.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/susantoj/powerfactory_python/issues/2?email_source=notifications&email_token=ANFZYWE66TU77DKBEDCDF2TQJ5INTA5CNFSM4IWQZN72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6YTS5Y#issuecomment-531708279, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANFZYWAMC4SJ4Q2JKAWKDO3QJ5INTANCNFSM4IWQZN7Q.

Johnaristidou commented 4 years ago

Also it gives me an error for unresolved referrence to powerfactory module.The path to powerfactory module is correct but I don't know why.

In addition after import powerfactory line if I type powerfactory. I cannot see any methods or variables which it provides

Get Outlook for Androidhttps://aka.ms/ghei36


From: Ioannis Aristidou Sent: Monday, September 16, 2019 12:48:17 PM To: susantoj/powerfactory_python reply@reply.github.com; susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

I activated it and then I executed my code in pycharm.I also tested helloworld.py script where is just a printing but it executed only in powerfactory

Get Outlook for Androidhttps://aka.ms/ghei36


From: Peace L notifications@github.com Sent: Monday, September 16, 2019 12:43:53 PM To: susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Ioannis Aristidou aristidou.ioannis@ucy.ac.cy; Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Traceback (most recent call last): File "C:/Users/CS8675/PycharmProjects/DIGSILENT/test.py", line 6, in lines = app.GetCalcRelevantObjects("*.ElmLne") AttributeError: 'NoneType' object has no attribute 'GetCalcRelevantObjects'

It means your 'app' instance does not have an active object which has GetCalcRelevantObjects', from your posted code it means you don't have an active project. You didn't activate your project.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/susantoj/powerfactory_python/issues/2?email_source=notifications&email_token=ANFZYWE66TU77DKBEDCDF2TQJ5INTA5CNFSM4IWQZN72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6YTS5Y#issuecomment-531708279, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANFZYWAMC4SJ4Q2JKAWKDO3QJ5INTANCNFSM4IWQZN7Q.

Johnaristidou commented 4 years ago

Furthermore I noticed in tutorial guide where it says that python scripts can only be executed internally or externally only in powerfactory.

Maybe powerfactory module is not available for externally use.I mean that I cannot execute scripts using powerfactory module outside powerfactory

Am I correct?

Get Outlook for Androidhttps://aka.ms/ghei36


From: Ioannis Aristidou Sent: Monday, September 16, 2019 12:56:59 PM To: susantoj/powerfactory_python reply@reply.github.com; susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Also it gives me an error for unresolved referrence to powerfactory module.The path to powerfactory module is correct but I don't know why.

In addition after import powerfactory line if I type powerfactory. I cannot see any methods or variables which it provides

Get Outlook for Androidhttps://aka.ms/ghei36


From: Ioannis Aristidou Sent: Monday, September 16, 2019 12:48:17 PM To: susantoj/powerfactory_python reply@reply.github.com; susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

I activated it and then I executed my code in pycharm.I also tested helloworld.py script where is just a printing but it executed only in powerfactory

Get Outlook for Androidhttps://aka.ms/ghei36


From: Peace L notifications@github.com Sent: Monday, September 16, 2019 12:43:53 PM To: susantoj/powerfactory_python powerfactory_python@noreply.github.com Cc: Ioannis Aristidou aristidou.ioannis@ucy.ac.cy; Author author@noreply.github.com Subject: Re: [susantoj/powerfactory_python] EXECUTION OF .py FILES (#2)

Traceback (most recent call last): File "C:/Users/CS8675/PycharmProjects/DIGSILENT/test.py", line 6, in lines = app.GetCalcRelevantObjects("*.ElmLne") AttributeError: 'NoneType' object has no attribute 'GetCalcRelevantObjects'

It means your 'app' instance does not have an active object which has GetCalcRelevantObjects', from your posted code it means you don't have an active project. You didn't activate your project.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/susantoj/powerfactory_python/issues/2?email_source=notifications&email_token=ANFZYWE66TU77DKBEDCDF2TQJ5INTA5CNFSM4IWQZN72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6YTS5Y#issuecomment-531708279, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANFZYWAMC4SJ4Q2JKAWKDO3QJ5INTANCNFSM4IWQZN7Q.

SjorsHijgenaar commented 2 years ago

Did you ever manage to find out how to get this working? I'm running into the same issues, only I'm using VS Code instead of PyCharm. HelloWorld script executes fine from within PowerFactory, but if I run from VS Code, I get the same

AttributeError: 'NoneType' object has no attribute 'PrintPlain'

Wondering if anyone has a fix for this.

peace899 commented 2 years ago

Did you ever manage to find out how to get this working? I'm running into the same issues, only I'm using VS Code instead of PyCharm. HelloWorld script executes fine from within PowerFactory, but if I run from VS Code, I get the same

AttributeError: 'NoneType' object has no attribute 'PrintPlain'

Wondering if anyone has a fix for this.

Run it directly with the interpreter by including: if __name__ == __main__

import sys
sys.path.append(PF_directory)

def main():
    #Your Code here

if __name__ == '__main__':
    import powerfactory as pf
    app = pf.GetApplication()
    main()
SjorsHijgenaar commented 2 years ago

I found out that it was working fine, but it's not possible to execute the script while an instance of PowerFactory is running. I was trying to run them simultaneously.