# Copyright (c) 2026 JSOL CORPORATION
#
# 本スクリプトはMITライセンスのもとで公開しています。
# ライセンス全文は以下を参照してください。
# https://www.jmag-international.com/jp/scriptlibrary/jmag_script_library_mit/

app = designer.GetApplication()

def createVectorExpression(study, vectorExprInfo):
    """ベクトルデータを使用した変数、式の作成"""
    exprtype = vectorExprInfo[u"type"]
    exprParam = vectorExprInfo[u"param"]
    vectExpr = study.CreateVectorExpression(vectorExprInfo[u"title"])
    # データセットから作成
    if exprtype == u"DataVariable":
        vectExpr.SetReferenceDataFromTable(exprParam[u"refDataFromTbl"])
        vectExpr.SetUnit(exprParam[u"unit"])
        vectExpr.SetLine(exprParam[u"line"])
        vectExpr.SetVariable(exprParam[u"variable"])
        vectExpr.SetCaseRangeType(exprParam[u"caseRangeType"])
    # 式の作成
    elif exprtype == u"Expression":
        vectExpr.SetVariable(exprParam[u"variable"])
        vectExpr.SetExpression(exprParam[u"expression"])

study = app.GetCurrentStudy()
dataVarParam = {
    u"type" : u"DataVariable",
    u"title" : u"rth1",
    u"param" : {  u"refDataFromTbl" : u"回路の熱抵抗",
                  u"unit" : u"s",
                  u"line" : u"Rt1",
                  u"variable" : u"RtRt1ve",
                  u"caseRangeType" : u"allsteps"
    }
}
createVectorExpression(study, dataVarParam)
exprParam = {
    u"type" : u"Expression",
    u"title" : u"rth2",
    u"param" : { u"variable" : u"RtCE1R2ve",
                 u"expression" : u"1 / RtRt1ve"
    }
}
createVectorExpression(study, exprParam)
