# 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/ def setUserSubAndSubroutineParameter(study): """Set user subroutines and subroutine parameters""" study.GetStudyProperties().SetValue(u"UsrsubName", u"default") study.AddSubroutineParameter(u"paramInt1", u"5") study.AddSubroutineParameter(u"paramInt2", u"12") study.AddSubroutineParameter(u"ParamDouble1", u"ELPotentialVal") def getCircuitInStudy(study): """Retrieve the Circuit object from the study.if it does not exist, create a new circuit""" if study.HasCircuit(): circuit = study.GetCircuit() else: circuit = study.CreateCircuit() return circuit def setUserSubroutineInCircuit(circuit, targetCompName): """Place the Electric Potential source (1 terminal) element in the circuit and configure the user subroutine""" VSComp = circuit.CreateComponent(u"VoltageSource", targetCompName) circuit.CreateComponentInstance(VSComp, -9, 7) VSComp.SetValue(u"XType", u"UserSub") VSComp.SetValue(u"userid", -1) app = designer.GetApplication() study = app.GetCurrentStudy() setUserSubAndSubroutineParameter(study) circuit = getCircuitInStudy(study) targetCompName = u"VS" setUserSubroutineInCircuit(circuit, targetCompName)