Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IFRs on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screenshots from results in NXOpen

Status
Not open for further replies.

bebopsan

Aerospace
Sep 13, 2012
3
Hello!

I am trying to use a journal script in NXOpen to loop through simulation files and take snapshots of the simulation results in order to create an animation of solutions where I make small variations to a part and then solve.
Up to now the code I have is able to open the sim files and take snapshots with the command:

Code:
Dim ufs As UFSession = UFSession.GetUFSession
ufs.Disp.CreateImage

But the script is not displaying the results and the snapshots I get are just snapshots of the part as seen in the screen before solving.
I've tried recording journals where I open one of the solutions and modify the color bar for scaling, but when I replay them there is just a quick flash and I only see the part as would be in the simulation enviroment.

Code:
' NX 7.5.0.32
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
    Sub Main()
        For SparPlacement As Integer = -300 To 200 Step 50

            Dim ufs As UFSession = UFSession.GetUFSession
            Dim theSession As Session = Session.GetSession()
            ' ----------------------------------------------
            '   Menu: File->Open...
            ' ----------------------------------------------
            Dim basePart1 As BasePart
            Dim partLoadStatus1 As PartLoadStatus
            basePart1 = theSession.Parts.OpenBaseDisplay("Path to part \wReinforcement_sim1" & Str(SparPlacement) & ".sim", partLoadStatus1)
            partLoadStatus1.Dispose()
            Dim workSimPart As CAE.SimPart = CType(theSession.Parts.BaseWork, CAE.SimPart)
            Dim displaySimPart As CAE.SimPart = CType(theSession.Parts.BaseDisplay, CAE.SimPart)
            Dim simPart1 As CAE.SimPart = CType(workSimPart, CAE.SimPart)
            theSession.Post.UpdateUserGroupsFromSimPart(simPart1)
            Dim simSimulation1 As CAE.SimSimulation = CType(workSimPart.FindObject("Simulation"), CAE.SimSimulation)
            Dim simSolution1 As CAE.SimSolution = CType(simSimulation1.FindObject("Solution[Solution 1]"), CAE.SimSolution)
            Dim theResultManager As CAE.ResultManager = theSession.ResultManager()
            Dim solResults As CAE.SolutionResult = theResultManager.CreateSolutionResult(simSolution1)
            Dim result As CAE.Result = CType(solResults, CAE.Result)
            Dim solutionResult1 As CAE.SolutionResult
            solutionResult1 = theSession.ResultManager.CreateSolutionResult(simSolution1)
            Dim resultParameters1 As CAE.ResultParameters
            resultParameters1 = theSession.ResultManager.CreateResultParameters()
            Dim loadcase1 As CAE.Loadcase = CType(solutionResult1.Find("Loadcase[Load Case 1]"), CAE.Loadcase)
            Dim iteration1 As CAE.Iteration = CType(loadcase1.Find("Iteration[Static Step 1]"), CAE.Iteration)
            Dim resultType1 As CAE.ResultType = CType(iteration1.Find("ResultType[Ply Stress - Elemental]"), CAE.ResultType)
            resultParameters1.SetGenericResultType(resultType1)
            resultParameters1.SetResultBeamSection(-1)
            resultParameters1.SetResultShellSection(-1)
            resultParameters1.SetResultComponent(-1)
            resultParameters1.SetCoordinateSystem(CAE.Result.CoordinateSystem.AbsoluteRectangular)
            resultParameters1.SetBeamResultsInLocalCoordinateSystem(True)
            resultParameters1.MakeElementResult(False)
            resultParameters1.SetElementValueCriterion(CAE.Result.ElementValueCriterion.Average)
            Dim average1 As CAE.Result.Averaging
            average1.DoAveraging = False
            average1.AverageAcrossPropertyIds = True
            average1.AverageAcrossMaterialIds = True
            average1.AverageAcrossElementTypes = True
            average1.AverageAcrossFeatangle = True
            average1.AverageAcrossAnglevalue = 45.0
            average1.IncludeInternalElementContributions = True
            resultParameters1.SetAveragingCriteria(average1)
            resultParameters1.SetComplexCriterion(CAE.Result.Complex.Amplitude)
            resultParameters1.SetPhaseAngle(0.0)
            resultParameters1.SetSectionPlyLayer(1, 0, 1)
            resultParameters1.SetScale(1.0)
            Dim unit5 As Unit = CType(workSimPart.UnitCollection.FindObject("MilliMeter"), Unit)
            resultParameters1.SetUnit(unit5)
            resultParameters1.SetAbsoluteValue(False)
            resultParameters1.SetCalculateBeamStrResults(False)
            resultParameters1.SetBeamFillets(True)
            resultParameters1.SetBeamFilletRadius(0.5)
            resultParameters1.DisplayMidnodeValue(True)
            Dim postviewId1 As Integer
            postviewId1 = theSession.Post.CreatePostviewForResult(0, solutionResult1, False, resultParameters1)
            Dim lw As ListingWindow = theSession.ListingWindow
            lw.Open()
            lw.WriteLine("Post View ID is: " + postviewId1.ToString())
            theSession.ResultManager.DeleteResultParameters(resultParameters1)

            ' ----------------------------------------------
            '   Menu: Tools->Results->Edit Post View...
            ' ---------------------------------------------

            Dim colorbar1 As CAE.Post.Colorbar
            colorbar1.Spectrum = CAE.Post.Spectrum.Structural
            colorbar1.InvertSpectrum = False
            colorbar1.Scale = CAE.Post.Scale.Automatic
            colorbar1.NumberOfLevels = 12
            colorbar1.Threshold = CAE.Post.Threshold.Specified
            colorbar1.ThresholdMinimum = 0.11715445667505
            colorbar1.ThresholdMaximum = 30.2787322998
            colorbar1.ShowOverflowAbove = False
            colorbar1.ShowOverflowBelow = False
            colorbar1.OverflowAboveColor = workSimPart.Colors.Find("Silver Gray")
            colorbar1.OverflowBelowColor = workSimPart.Colors.Find("Dark Gray")
            colorbar1.Position = CAE.Post.Position.Left
            theSession.Post.PostviewSetColorbar(postviewId1, colorbar1)

            Dim primaryEdgeface1 As CAE.Post.EdgeFace
            primaryEdgeface1.EdgeStyle = CAE.Post.EdgeStyle.External
            primaryEdgeface1.EdgeColor = workSimPart.Colors.Find("Granite Gray")
            primaryEdgeface1.FaceStyle = CAE.Post.FaceStyle.Opaque
            primaryEdgeface1.FaceColor = workSimPart.Colors.Find("Silver Gray")
            Dim undeformedEdgeface1 As CAE.Post.EdgeFace
            undeformedEdgeface1.EdgeStyle = CAE.Post.EdgeStyle.Feature
            undeformedEdgeface1.EdgeColor = workSimPart.Colors.Find("Granite Gray")
            undeformedEdgeface1.FaceStyle = CAE.Post.FaceStyle.Translucent
            undeformedEdgeface1.FaceColor = workSimPart.Colors.Find("Silver Gray")
            theSession.Post.PostviewSetEdgeFace(postviewId1, primaryEdgeface1, undeformedEdgeface1)

            Dim text1 As CAE.Post.Text
            text1.Font = 0
            text1.Size = 0
            text1.Color = workSimPart.Colors.Find("Deep Steel")
            text1.Bold = 0
            theSession.Post.PostviewSetText(postviewId1, text1)

            theSession.Post.PostviewSetFormat(postviewId1, CAE.Post.Format.Auto, 4)

            Dim annotationBox1 As CAE.Post.AnnotationBox
            annotationBox1.LineColor = workSimPart.Colors.Find("White")
            annotationBox1.AreaColor = workSimPart.Colors.Find("Deep Steel")
            annotationBox1.ShowBorder = True
            annotationBox1.FillArea = True
            annotationBox1.AreaTranslucency = False
            theSession.Post.PostviewSetAnnotationBox(postviewId1, annotationBox1)

            theSession.Post.PostviewUpdate(postviewId1)
            ufs.Disp.CreateImage("Path to image\Something" + Str(SparPlacement), UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)
        Next

    End Sub
    ''Function GetResultAccess(ByRef result As CAE.Result, ByVal loadCaseIdx As Integer, ByVal iterationIdx As Integer, ByVal scale As Double) As CAE.ResultAccess

    'End Function

End Module

Has anyone encountered this same problem? Or know a better way of doing something simmilar?

Thanks beforehand.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor