Menu

How to access objects in a linked DWSIM subflowsheet via Python?

Natalie
2018-02-21
2018-06-14
  • Natalie

    Natalie - 2018-02-21

    Hi Daniel,

    I just started scripting with Python, so I am not experienced, yet. I tried to handle the following topic without success. Hopefully you have an advice for me. Here is what I intend to do: Set properties (e.g. properties related to thermal and hydraulic profiles) for objects within linked DWSIM subflowsheets. The idea is to govern model
    parametrization - especially for the subflowsheets - via a main Python script. How can I access objects from a DWSIM subflowsheet (a seperate dwxmz simulation projekt) that is linked via
    a "Flowsheet Unit Operation object")? I tried it in two ways:

    1. Using the "SetPropertyValue" function (http://dwsim.inforside.com.br/api_help5/html/M_DWSIM_Interfaces_IAttachedUtility_SetPropertyValue.htm). It worked out perfectly to set properties for an object in the according main flowsheet. However, it didn't work out to set properties for objects in linked DWSIM subflowsheets. To my knowledge, the related subflowsheets are linked correctly to the main flowsheet (using the control panel), as they react according to simulation settings changed in the main flowsheet.
    2. also tried to open and rule the required DWSIM subflowsheet by the function open(), by providing the filepath of the related DWSIM subflowsheets, neither did this work.

    What would you suggest?

    Thank you and best regards
    Nata

     
  • Natalie

    Natalie - 2018-03-19

    Hi Daniel,

    thank you very much!

    Regards,
    Natalie

     
  • Natalie

    Natalie - 2018-05-15

    Hi Daniel,

    again, thanks for your reply.

    I have tried to work out a solution according to your suggestion; unfortunately, I could not get it running. Is it possible you send me a short Python syntax example, where e.g., a property value of an arbitrary object contained in another DWSIM flowsheet (e.g. DWSIM subflowsheet) is modified or set in the script command?

    Thank you and kind regards,
    Natalie

     
  • Daniel Medeiros

    Daniel Medeiros - 2018-05-15

    Sure, Natalie. Open the Flowsheet Unit Operation Sample and try this script:

    mainfs = Flowsheet.GetFlowsheetSimulationObject('FS-000')
    
    subfs = mainfs.Fsheet
    
    outletvapor = subfs.GetFlowsheetSimulationObject('vapor')
    
    vapor_flow = outletvapor.GetPhase('Overall').Properties.massflow
    
    print str(vapor_flow)
    
     
  • Natalie

    Natalie - 2018-05-24

    Hi Daniel, thanks a lot!
    Regards, Natalie

     
  • Ja Eddouibi

    Ja Eddouibi - 2018-06-13

    Hi Mr. Medeiros
    I plan to use Ironpython to develop dynamic models for some unit operations. In order to get there, i started with using the example of the heat exchanger posted in the following link: http://dwsim.inforside.com.br/wiki/index.php?title=Dynamic_Simulation_Tutorial_with_DWSIM_and_Python,_Part_3:_Adding_a_PID_Controller
    But when i tried to compile the script corresponding to this example i got errors in lines 6 and 16 as illustrated in the attached picture. Can you tell me how can i deal with issue ?
    kindly

     
    • Daniel Medeiros

      Daniel Medeiros - 2018-06-13

      You have to run this sample from the Cross-Platform UI. The 'SupressMessages' property is available only on it.

       
  • Ja Eddouibi

    Ja Eddouibi - 2018-06-14

    Hi Daniel,
    I tried the same code from UI but i still get the same problem. I think that the problem is probably due to the DWSIM version that i use. Can you send me the version you used (precicely the update reference) .
    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.