Ask Your Question
0

Create User DLL can't work

asked 2021-08-24 20:37:34 -0500

HSU gravatar image

updated 2021-08-27 21:43:19 -0500

Hello everyone, I'm new in learning user defined model. I'm trying to compile the DEMOEX by using "Create User DLL",but when I follow the PSSE environment manager user guide to run "psseenvmanager_w.pyw" here comes a problem.

Traceback (most recent call last): File "C:\Python27\Lib\site-packages\psseenvmanager\psseenvmanagerw.pyw", line 6, in <module> import commonem as comonpy ImportError: DLL load failed:The specified module could not be found.

I wondering if "common_em" is a package of python, when check my "pip list" there exist common(0.1.2),it is the same thing?

import os
import sys
PSSE_PATH = r"C:\Program Files (x86)\PTI\PSSE34\PSSBIN"
sys.path.append(PSSE_PATH)
os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_PATH
import psspy

from psspy import _i
from psspy import _f

psspy.psseinit(100000)
psspy.case(r"""C:\Program Files (x86)\PTI\PSSE33\EXAMPLE\savnw.sav""")
psspy.fdns([0,0,0,1,1,0,99,0])
psspy.fdns([0,0,0,1,1,0,99,0])
psspy.cong(0)
psspy.conl(0,1,1,[0,0],[ 100.0,0.0,0.0, 100.0])
psspy.conl(0,1,2,[0,0],[ 100.0,0.0,0.0, 100.0])
psspy.conl(0,1,3,[0,0],[ 100.0,0.0,0.0, 100.0])
psspy.ordr(0)
psspy.fact()
psspy.tysl(0)
psspy.dyre_new([1,1,1,1],r"""C:\Program Files (x86)\PTI\PSSE33\EXAMPLE\savnw.dyr""","","","")
#-----------load dll--------------------  
workdir = os.getcwd()
dllname= 'dsusr_34.dll'
ierr = psspy.addmodellibrary(workdir + "\\" + dllname)      #load dll   
#---------------------------------------- 
psspy.chsb(0,1,[-1,-1,-1,1,4,0])
psspy.chsb(0,1,[-1,-1,-1,1,5,0])
psspy.chsb(0,1,[-1,-1,-1,1,13,0])
psspy.chsb(0,1,[-1,-1,-1,1,16,0])
psspy.strt_2([0,1],r"""C:\Users\EE106\Desktop\try.out""")

could anyone can help me fix it? Very apperciate!! My PSSE version is 34.6.1

Messages for api ADDMODELLIBRARY Library not found (000301) "C:\Python27\Lib\site-packages\psseenvmanager\dsusr_34.dll"

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2021-08-25 17:12:45 -0500

jconto gravatar image

updated 2021-08-27 09:08:46 -0500

I prefer to use "create_dll.py". DLL creation works with the code below. Run it from a CMD window (not within PSSe GUI). Edit it to suit your case:

#candl.py
'''Create a UDM DLL.
It adds all *.flx, *.f,...,*.obj, *.lib files in working directory
to create a dll file.

default vars:
    keyname = 'dsusr'
    psseversion = 34

Open a "PSSe enabled" CMD window at your working folder,
    - To use with default parameters (edit lines 26-29 for updates), run it as:
        c:\..>python candl.py

    - To enter a dll name mymodel, run it as:
        c:\..>python candl.py mymodel
'''
import os, sys
import psse_env_manager
#__________________________________________________________________
def find_files(pattern,search_path=''):
    import glob
    """Given a search path, yield all files matching the pattern"""
    return glob.glob(os.path.join(search_path,pattern))
#______________________________________________________________
# [vars]
psseversion = 34
keyname = 'dsusr'
mypathlib = False  # set PATH and LIB values using installed components
src_lst = []                

work_dir= os.getcwd()
if len(sys.argv)>1:
   keyname = sys.argv[1]
dllname= "%s_%s.dll"%(keyname,psseversion)
dlllib = dllname.replace('.dll','.lib')
try: os.remove(dlllib)
except: pass

for ext in ['*.flx','*.f','*.for','*.f90']:       #include conec & conet files
    src_lst += find_files(ext,work_dir)           #get source files
objlibfiles  = find_files('*.obj',work_dir)
objlibfiles += find_files('*.lib',work_dir)

ierr = psse_env_manager.create_dll(psseversion, 
                                   src_lst, 
                                   modsources =[], 
                                   objlibfiles=objlibfiles, 
                                   dllname=dllname,
                                   workdir=work_dir, 
                                   showprg=True, 
                                   useivfvrsn ='latest', 
                                   shortname  = keyname,
                                   description='User Model', 
                                   majorversion=1, 
                                   minorversion=0, 
                                   buildversion=0, 
                                   companyname='',
                                   mypathlib=mypathlib)

Once the dll is created, load it with the python script performing the dynamic run, just before initialization, as:

import psspy
...
workdir = os.getcwd()
dllname= 'demoex.dll'
ierr = psspy.addmodellibrary(workdir + "\\" + dllname)          #load dll
...
psspy.strt(1,'outfile.out')            #initialization
edit flag offensive delete link more

Comments

Thanks your reply. Now I can use DEMOEX to create dll file by "create_dll.py",But when I try load dll into PSSE,it's show " Library not found (000301) " . how to fix it? thanks

HSU gravatar imageHSU ( 2021-08-26 04:00:32 -0500 )edit

try adding the full path for the dll file. If it does not help, show your script and your folder tree.

jconto gravatar imagejconto ( 2021-08-26 11:02:17 -0500 )edit

Sorry sir, I really new on writing it. Can I ask more detail about "adding the full path for dll file"? Is it adding in the "create_dll.py" or adding in the "DEMOEX.f" ? And where to add if the path should add in "create_dll.py"? Very appreciate of your help.

HSU gravatar imageHSU ( 2021-08-26 19:22:06 -0500 )edit

See my feedback on my answer above.

jconto gravatar imagejconto ( 2021-08-27 09:10:15 -0500 )edit

Thanks your reply, but it seem have the same problem when I run the code above. If there anything need to correct, please kindly tell me. Very appreciate of your help.

HSU gravatar imageHSU ( 2021-08-27 21:49:21 -0500 )edit

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: 2021-08-24 20:37:34 -0500

Seen: 155 times

Last updated: Aug 27