How to use Jython script to import and export csv file in instance table

Hello Commumity,

I want to implement simulation of an instance table automatically .

After automatically create an instance table(classfier and header are ready), now I would like to use Jython to import the data from csv (Same function as Excel/Csv file->select file -> csv) , after simulation done, export all the simulation result to csv file.

Here is my question:

  1. Is there any Open API for import csv.
  2. I use following script to do the export, but it can execute without error but no csv is exported. Can anyone help me. Thanks
    from com.nomagic.magicdraw.core import Application
    from com.nomagic.magicdraw.simulation import SimulationManager, SimulationProfile
    from com.nomagic.magicdraw.openapi.uml import SessionManager

    app = Application.getInstance()
    project = app.getProject()
    log = app.getGUILog()

    diagram = project.getActiveDiagram()

    if diagram and diagram.getHumanType() == "Instance Table":
       table_el = diagram.getElement()
       
       sm = SessionManager.getInstance()
       session_opened = False
       try:
           
           if not sm.isSessionCreated():
               sm.createSession(" CSVExport")
               session_opened = True

           
           wrapper = SimulationProfile.getInstance(table_el)
           csv_wrap = wrapper.csvExport()
           
           if csv_wrap is None:
               log.log("CSVExportStereotype is none")
           else:
               log.log("CSVExportStereotype found: %s" % csv_wrap)
               
               csv_wrap.setFileName(table_el, "C:/export.csv") 
               csv_wrap.setWriteAtTheEnd(table_el, True)
               log.log("DONE")
           
       finally:
           if session_opened:
               sm.closeSession()
               log.log("Session closed")
       

       SimulationManager.execute(table_el, True)
       log.log("Simulation executed, CSV should be exported.")
    else:
       log.log("Error")