# Copyright (c) 2026 JSOL CORPORATION # # This script is released under the MIT License. # See the full license text at: # https://www.jmag-international.com/scriptlibrary/jmag_script_library_mit/ import os app = designer.GetApplication() def createLamiMagFluxDensityProbe(study, title): """Create a magnetic flux density (stacked) probe.""" probe = study.CreateProbe(title) probe.SetAutoRecalculate(False) probe.SetResultType(u"LaminationMagneticFluxDensity") # The 1st argument of SetResultCoordinate # Name or index # The name of the preset coordinate system is fixed according to the language setting. # The index is specified in a 0-based from the coordinate system definition list order under Project - Model - Coordinate Systems probe.SetResultCoordinate(0) # probe.SetResultCoordinate(u"Global Rectangular") probe.SetComponent(u"All") probe.SetLocationCoordinate(0) # probe.SetLocationCoordinate(u"Global Rectangular") probe.SetProbeType(u"Coordinate") probe.SetLocation(0, u"-58", u"9", u"0") probe.RenamePoint(0, u"Measurement position") probe.SetUseElementValue(True) probe.SetMoveWithPart(True) probe.Build() return probe def createAvgVsDepth(dataManager, probe, param): """Create the necessary parameters for averaging by depth.""" parameter = app.CreateGraphIntegralParameter(param[u"title"]) dataSet = probe.GetDataSet() parameter.AddDataSet(dataSet) parameter.SetMin(param[u"min"]) parameter.SetMax(param[u"max"]) parameter.SetRangeUnit(param[u"rangeUnit"]) dataSetAVGVsDepth = dataManager.CreateAverageVersusDepth(parameter) graphModelAVGVsDepth = dataManager.CreateGraphModel(dataSetAVGVsDepth) return graphModelAVGVsDepth def getFolderpathOfOpenedProjectFile(): """Get the folder path of the currently open jproj file.""" openedJprojFilePath = app.GetProjectPath() folderPath = os.path.dirname(openedJprojFilePath) return folderPath def exportAvgVsDepth(graphModelAVGVsDepth, exportPath): """Export the average for each depth.""" graphModelAVGVsDepth.WriteTable(os.path.join(exportPath, u"avgVsDepth.csv")) study = app.GetCurrentStudy() probeTitle = u"B-lamination" probe = createLamiMagFluxDensityProbe(study, probeTitle) dataManager = app.GetDataManager() dataSetTitle = u"B-lamination AVG" param = { u"title" : dataSetTitle, u"min" : u"0", u"max" : u"0.02", u"rangeUnit" : u"s" } graphModelAVGVsDepth = createAvgVsDepth(dataManager, probe, param) exportPath = getFolderpathOfOpenedProjectFile() exportAvgVsDepth(graphModelAVGVsDepth, exportPath)