In Script Manager one can add several scripts!
Is there any way one script use another? I mean if we implement solver in one script and want to call it from another, how is this possible in DWSIM?
For Custom Unit Operation, DWSIM create two windows under script: they are called: Script and Includes
Is it possible to add user libraries, user solver and codes to be used in the Script? I mean by import keyword!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you Daniel!
Does this mean if I have a solver in tab 2 for example to solve a BVP the I have to add that code to be able to call it in tab 1:
importclrimportSystemfromSystemimport*clr.AddReference('System.Core')clr.ImportExtensions(System.Linq)# get the script text from "Functions" using LINQsource=Flowsheet.Scripts.Values.Where(lambdax:x.Title=='Functions').FirstOrDefault().ScriptText.replace('\r','')# execute the scriptexec(source)
Why not use import mylib if tab 2 has name mylib?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think I am able to successfully import user modules (when stored on disk) in DWSIM (both through UO script editor, and main Script Manager)
Example 1: Use absolute path
Assume you have user modules in G:\DWSIM\python\read-write-object-data\libs and want to use in your simulation
# Import modules by adding absolute pathimportsyssys.path.append(r'G:\DWSIM\python\read-write-object-data\libs')Flowsheet.WriteMessage(str(sys.path))importmylibx=mylib.RgFlowsheet.WriteMessage(str(x))Flowsheet.WriteMessage("finished successfully...")
Example 2: Use relative path
Assume you have user modules in libs directory which is located as a child or sub directory with respect to the current simulation file and want to use your module in your simulation
Here using the home = Flowsheet.FilePath the absolute path of current simulation is retrieved! and then after removing the file name the calculated path is added to module search path! you can then add your sub directory or ant path relative to the current simulation path!
Those write messages are only for demo.
Last edit: Mohammad 2021-08-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In Script Manager one can add several scripts!
Is there any way one script use another? I mean if we implement solver in one script and want to call it from another, how is this possible in DWSIM?
For Custom Unit Operation, DWSIM create two windows under script: they are called: Script and Includes
Is it possible to add user libraries, user solver and codes to be used in the Script? I mean by import keyword!
https://dwsim.inforside.com.br/wiki/index.php?title=IronPython_Script_Snippets#Executing_a_script_from_another_tab.2Fsection
Thank you Daniel!
Does this mean if I have a solver in tab 2 for example to solve a BVP the I have to add that code to be able to call it in tab 1:
Why not use
import mylib
if tab 2 has namemylib
?Honestly I don't know how to use import with libraries in other tabs...
Thank you for your prompt reply! I will update you here if I can find any better solution!
Hi Daniel,
I think I am able to successfully import user modules (when stored on disk) in DWSIM (both through UO script editor, and main Script Manager)
Example 1: Use absolute path
Assume you have user modules in
G:\DWSIM\python\read-write-object-data\libs
and want to use in your simulationExample 2: Use relative path
Assume you have user modules in
libs
directory which is located as a child or sub directory with respect to the current simulation file and want to use your module in your simulationHere using the
home = Flowsheet.FilePath
the absolute path of current simulation is retrieved! and then after removing the file name the calculated path is added to module search path! you can then add your sub directory or ant path relative to the current simulation path!Last edit: Mohammad 2021-08-27
Daniel
This worth to be documented! If Flowsheet can expose its home directory then the above solution is much more easier!