Menu

Access to Script Manager without opening DWSIM

Ella Daiki
2023-03-06
2023-04-27
  • Ella Daiki

    Ella Daiki - 2023-03-06

    Hey all,

    I have a question about the Script Manager. I would like to access the script manager in DWSIM via python and add my own kinetics.

    The User-Guide only explains how to use script manager in DWSIM but my question is, how to access the Script Manager via Python and switch from 'simple' to 'advanced' reaction specification, without opening the software.

    Thanks a lot!!!

     

    Last edit: Ella Daiki 2023-03-10
  • Daniel Medeiros

    Daniel Medeiros - 2023-03-11
    myreaction = Flowsheet.GetReaction('myreaction')
    
    myscripttitle = 'myscript'
    
    myscript = Flowsheet.Scripts[myscripttitle]
    
    myscript.ScriptText = 'something'
    
    myreaction.ReactionKinetics = 1 # script
    myreaction.ScriptTitle = myscripttitle
    
     
  • Ella Daiki

    Ella Daiki - 2023-03-13

    Thanks a lot.

    interf = Automation3()
    Flowsheet = interf.CreateFlowsheet()
    myreaction = Flowsheet.GetReaction('myreaction')
    myscripttitle = 'myscript'
    myscript = Flowsheet.Scripts[myscripttitle]
    

    The last Line is causing an error:

    KeyNotFoundException: The specified key was not given in the dictionary. bei System.ThrowHelper.ThrowKeyNotFoundException(). bei System.Collections.Generic.Dictionary'2.get_Item(TKey key)

    But 'myscripttitle' appears as saved in the Variable Explorer of Python.
    Regards.

     
    • Daniel Medeiros

      Daniel Medeiros - 2023-03-13

      You must replace 'myreaction' and 'myscript' with the actual titles from your own simulation.

       
      • Ella Daiki

        Ella Daiki - 2023-04-07

        Thanks for the answer.
        But I still have an error:

        File [...] in <module> myreaction.ReactionKinetics = 1 # script
        TypeError: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(intvalue)</module>

        Is there perhaps a module missing?
        (running python version 3.9.13, if it matters)
        Thanks again.

         
  • abbas555

    abbas555 - 2023-04-27

    Hi,
    I found a post saying that an update of python can solve the problem. So I executed the code once with 3.9 and 3.10, but I still get the same Error: TypeError: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(intvalue)

    Is there any other way to execute a Script from Script Manager, using python?

    Best regards

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.