# NX 2412
# Journal created by antoi on Sat Nov 15 12:34:27 2025 Eastern Standard Time
#
import math
import NXOpen
import NXOpen.CAE
def main(args) : 

    theSession  = NXOpen.Session.GetSession() #type: NXOpen.Session
    workSimPart = theSession.Parts.BaseWork
    displaySimPart = theSession.Parts.BaseDisplay
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Change Displayed Part")
    
    part1 = theSession.Parts.FindObject("Bracket")
    baseTemplateManager1 = theSession.XYPlotManager.TemplateManager
    
    status1, partLoadStatus1 = theSession.Parts.SetActiveDisplay(part1, NXOpen.DisplayPartOption.AllowAdditional, NXOpen.PartDisplayPartWorkPartOption.UseLast)
    
    workSimPart = NXOpen.BasePart.Null
    workPart = theSession.Parts.Work
    displaySimPart = NXOpen.BasePart.Null
    displayPart = theSession.Parts.Display
    partLoadStatus1.Dispose()
    # ----------------------------------------------
    #   Menu: Tools->Utilities->Expressions...
    # ----------------------------------------------
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
    
    theSession.SetUndoMarkName(markId2, "Expressions Dialog")
    
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Edit Expression")
    
    expression1 = workPart.Expressions.FindObject("support_angle")
    unit1 = workPart.UnitCollection.FindObject("Degrees")
    workPart.Expressions.EditExpressionWithUnits(expression1, unit1, "36")
    
    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Expressions")
    
    theSession.DeleteUndoMark(markId4, None)
    
    markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Expressions")
    
    markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Make Up to Date")
    
    objects1 = [NXOpen.NXObject.Null] * 1 
    objects1[0] = expression1
    theSession.UpdateManager.MakeUpToDate(objects1, markId6)
    
    markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "NX update")
    
    nErrs1 = theSession.UpdateManager.DoUpdate(markId7)
    
    theSession.DeleteUndoMark(markId7, "NX update")
    
    theSession.DeleteUndoMark(markId6, None)
    
    theSession.DeleteUndoMark(markId5, None)
    
    theSession.SetUndoMarkName(markId2, "Expressions")
    
    markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Change Displayed Part")
    
    simPart1 = theSession.Parts.FindObject("Bracket_sim1")
    status2, partLoadStatus2 = theSession.Parts.SetActiveDisplay(simPart1, NXOpen.DisplayPartOption.AllowAdditional, NXOpen.PartDisplayPartWorkPartOption.UseLast)
    
    workPart = NXOpen.Part.Null
    workSimPart = theSession.Parts.BaseWork # Bracket_sim1
    displayPart = NXOpen.Part.Null
    displaySimPart = theSession.Parts.BaseDisplay # Bracket_sim1
    partLoadStatus2.Dispose()
    markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Open in Window")
    
    femPart1 = theSession.Parts.FindObject("Bracket_fem1")
    baseTemplateManager2 = theSession.XYPlotManager.TemplateManager
    
    status3, partLoadStatus3 = theSession.Parts.SetActiveDisplay(femPart1, NXOpen.DisplayPartOption.AllowAdditional, NXOpen.PartDisplayPartWorkPartOption.SameAsDisplay)
    
    workFemPart = theSession.Parts.BaseWork
    displayFemPart = theSession.Parts.BaseDisplay
    partLoadStatus3.Dispose()
    # ----------------------------------------------
    #   Menu: Edit->Update
    # ----------------------------------------------
    markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Update FE Model")
    
    fEModel1 = workFemPart.FindObject("FEModel")
    fEModel1.UpdateFemodel()
    
    markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Change Displayed Part")
    
    status4, partLoadStatus4 = theSession.Parts.SetActiveDisplay(simPart1, NXOpen.DisplayPartOption.AllowAdditional, NXOpen.PartDisplayPartWorkPartOption.UseLast)
    
    workSimPart = theSession.Parts.BaseWork # Bracket_sim1
    displaySimPart = theSession.Parts.BaseDisplay # Bracket_sim1
    partLoadStatus4.Dispose()
    # ----------------------------------------------
    #   Menu: Analysis->Solve...
    # ----------------------------------------------
    markId12 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
    
    theSession.SetUndoMarkName(markId12, "Solve Dialog")
    
    markId13 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Solve")
    
    theSession.DeleteUndoMark(markId13, None)
    
    markId14 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Solve")
    
    theCAESimSolveManager = NXOpen.CAE.SimSolveManager.GetSimSolveManager(theSession)
    
    psolutions1 = [NXOpen.CAE.SimSolution.Null] * 1 
    simSimulation1 = workSimPart.FindObject("Simulation")
    simSolution1 = simSimulation1.FindObject("Solution[Solution 1]")
    psolutions1[0] = simSolution1
    numsolutionssolved1, numsolutionsfailed1, numsolutionsskipped1 = theCAESimSolveManager.SolveChainOfSolutions(psolutions1, NXOpen.CAE.SimSolution.SolveOption.Solve, NXOpen.CAE.SimSolution.SetupCheckOption.CompleteDeepCheckAndOutputErrors, NXOpen.CAE.SimSolution.SolveMode.Background)
    
    theSession.DeleteUndoMark(markId14, None)
    
    theSession.SetUndoMarkName(markId12, "Solve")
    
    # ----------------------------------------------
    #   Menu: File->Save
    # ----------------------------------------------
    simPart2 = workSimPart
    partSaveStatus1 = simPart2.Save(NXOpen.BasePart.SaveComponents.TrueValue, NXOpen.BasePart.CloseAfterSave.FalseValue)
    
    partSaveStatus1.Dispose()
    # ----------------------------------------------
    #   Menu: Tools->Automation->Journal->Stop Recording
    # ----------------------------------------------
    
if __name__ == '__main__':
    main(sys.argv[1:])