Menu

Script Manager vs. User Model Script Editor

Mohammad
2021-06-03
2021-06-12
  • Mohammad

    Mohammad - 2021-06-03

    Is there any difference between Script Manager and User Model Script Editor?

    I assume the User Model Script Editor is linked to a User Model Unit operation by default and you can read inlet ports, write to outlet ports and calculate it!

    On the other side the Script Manager lets you freely do calculation on any or all objects in DWSIM simulation and still you can link to a specific object!

    So, my question is: Can I use the two environments through Python Bridge (e.g. Python.NET) and do calculation? DWSIM allows me to use Python.NET in both environment but it seems there is limitation in Script Manager, is this true?

     

    Last edit: Mohammad 2021-06-03
  • Mohammad

    Mohammad - 2021-06-03

    More Inputs

    • I set the Python Bridge
    • I use Python.NET everywhere

    • DWSIM 6.5.3

    • Windows 10
    • Classic UI
    • Python 3.8

    PART i: User Model
    If I use the below code in User Model Script Editor

    import numpy as np
    import scipy as sp
    from matplotlib import pyplot as plt
    
    x=np.linspace(0, np.pi)
    y=np.sin(x)
    
    Flowsheet.WriteMessage("Solved ...")
    
    plt.plot(x,y)
    plt.show()
    

    It works like a charm and show the plot!

    PART ii

    If I use the above code (just copy paste) in Script Manager then I get the below error

    System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
       at System.Windows.Forms.Control.get_Handle()
       at System.Windows.Forms.ScrollBar.UpdateScrollInfo()
       at System.Windows.Forms.ScrollBar.set_Maximum(Int32 value)
       at System.Windows.Forms.DataGridView.ComputeLayoutShortcut(Boolean computeVisibleRows)
       at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut, Boolean computeVisibleRows, Boolean invalidInAdjustFillingColumns, Boolean repositionEditingControl)
       at System.Windows.Forms.DataGridView.ResetUIState(Boolean useRowShortcut, Boolean computeVisibleRows)
       at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PreNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow& dataGridViewRow, Boolean changeIsInsertion)
       at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount)
       at System.Windows.Forms.DataGridViewRowCollection.AddInternal(Boolean newRow, Object[] values)
       at DWSIM.FormFlowsheet.WriteToLog(String texto, Color cor, MessageType tipo, String exceptionID) in C:\Users\Daniel\source\repos\DanWBR\dwsim6\DWSIM\Forms\Flowsheet\FormFlowsheet.vb:line 805
       at DWSIM.FormScript._Closure$__234-0._Lambda$__2() in C:\Users\Daniel\source\repos\DanWBR\dwsim6\DWSIM\Forms\FormScript.vb:line 322
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at DWSIM.FormScript.RunScript_PythonNET(String scripttext, FormFlowsheet fsheet) in C:\Users\Daniel\source\repos\DanWBR\dwsim6\DWSIM\Forms\FormScript.vb:line 332
       at DWSIM.FormScript.Button1_Click(Object sender, EventArgs e) in C:\Users\Daniel\source\repos\DanWBR\dwsim6\DWSIM\Forms\FormScript.vb:line 169
       at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
       at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
       at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ToolStrip.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    ---> (Inner Exception #0) System.InvalidOperationException: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
       at System.Windows.Forms.Control.get_Handle()
       at System.Windows.Forms.ScrollBar.UpdateScrollInfo()
       at System.Windows.Forms.ScrollBar.set_Maximum(Int32 value)
       at System.Windows.Forms.DataGridView.ComputeLayoutShortcut(Boolean computeVisibleRows)
       at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut, Boolean computeVisibleRows, Boolean invalidInAdjustFillingColumns, Boolean repositionEditingControl)
       at System.Windows.Forms.DataGridView.ResetUIState(Boolean useRowShortcut, Boolean computeVisibleRows)
       at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PreNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow& dataGridViewRow, Boolean changeIsInsertion)
       at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount)
       at System.Windows.Forms.DataGridViewRowCollection.AddInternal(Boolean newRow, Object[] values)
       at DWSIM.FormFlowsheet.WriteToLog(String texto, Color cor, MessageType tipo, String exceptionID) in C:\Users\Daniel\source\repos\DanWBR\dwsim6\DWSIM\Forms\Flowsheet\FormFlowsheet.vb:line 805
       at DWSIM.FormScript._Closure$__234-0._Lambda$__2() in C:\Users\Daniel\source\repos\DanWBR\dwsim6\DWSIM\Forms\FormScript.vb:line 322
       at System.Threading.Tasks.Task.Execute()<---
    

    Question: Is there any limitation with Script Manager?

     

    Last edit: Mohammad 2021-06-03
  • Daniel Medeiros

    Daniel Medeiros - 2021-06-03

    this is a bug. I'll investigate.

     
    👍
    1
  • Mohammad

    Mohammad - 2021-06-12

    Hi Daniel,
    It would be much appreciated if you notify me when you had any solution for this!

    Best wishes

     
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.