The IronPython script main.py follows. This script defines all functions executed by the callbacks in the XML extension definition file:
The function
ImportModel
is invoked by the callback<onrefresh>
in the stepAnalysis
.The function
CreateAnalysis
is invoked by the callback<onupdate>
in the stepAnalysis
.The function
CreateReport
is invoked by the callback<onrefresh>
in the stepResults
.
def ImportModel(step): tui = ExtAPI.Application.ScriptByName("TUI") tui.SendCommand("""/file/read-case "{0}" """.format(System.IO.Path.Combine( ExtAPI.Extension.InstallDir,"final.cas"))) tui.SendCommand("""/display/mesh ok""") tui.SendCommand("""/display/views/restore-view right""") def CreateAnalysis(step): tui = ExtAPI.Application.ScriptByName("TUI") res = System.IO.Path.GetTempFileName() img = System.IO.Path.GetTempFileName()+".jpg" curve = System.IO.Path.GetTempFileName() tui.SendCommand("""/define/boundary-conditions/velocity-inlet inlet no no yes yes no {0} no 0""".format(step.Properties["velocity"].Value), True) tui.SendCommand("""/solve/initialize/hyb-initialization""", True) tui.SendCommand("""/solve/iterate 50""", True) tui.SendCommand("""/display/mesh ok""", True) tui.SendCommand("""/display/views/restore-view right""", True) tui.SendCommand("""/display/set/contours/filled-contours? yes""", True) tui.SendCommand("""/display/set/contours/surfaces wall inlet outlet ()""", True) tui.SendCommand("""/display/contour pressure 0 2""", True) tui.SendCommand("""/display/save-picture "{0}" """.format(img), True) tui.SendCommand("""/surface/rake-surface rake-5 0 0 0 0 0 1 50""", True) tui.SendCommand("""/plot/plot-direction 0 0 1""", True) tui.SendCommand("""/plot/plot yes "{0}" yes yes no no pressure yes 0 0 1 rake-5 ()""".format(curve), True) tui.SendCommand("""/report/surface-integrals/area-weighted-avg inlet () pressure yes "{0}" """.format(res), True) val = 0. n = 0; with System.IO.StreamReader(res) as reader: while n!=5: line = reader.ReadLine() if line!=None: n+=1 str = line.Substring(32) val = System.Double.Parse(str, System.Globalization.CultureInfo.InvariantCulture) x=[] y=[] n = 0; with System.IO.StreamReader(curve) as reader: while n!=5: line = reader.ReadLine() if line!=None: n+=1 while not line.StartsWith(")"): tab = line.Split("\t") x.Add(System.Double.Parse(tab[0], System.Globalization.CultureInfo.InvariantCulture)) y.Add(System.Double.Parse(tab[1], System.Globalization.CultureInfo.InvariantCulture)) line = reader.ReadLine() System.IO.File.Delete(res) System.IO.File.Delete(curve) step.NextStep.Properties["pressure"].Value = val step.NextStep.Attributes["img"] = img step.NextStep.Attributes["x"] = x step.NextStep.Attributes["y"] = y def CreateReport(step): graph = step.UserInterface.GetComponent("Chart") graph.Title("Static Pressure") graph.ShowLegend(False) graph.Plot(step.Attributes["x"], step.Attributes["y"], key="Static Pressure", color='g') help = step.UserInterface.GetComponent("Report") help.SetHtmlContent(ExtAPI.Extension.InstallDir,"""<center><img style="height:250px" src="{0}"></center>""".format(step.Attributes["img"]))