Using function GetResultForPostview()

To all

I am playing around with NX.CAE results and recorded a test journal. I am trying to access the results displayed on the screen using the function NXOpen.CAE.Post.GetResultForPostview(). From the doc

Public Sub GetResultForPostview (postviewId As Integer, _
ByRef result As Result, _
ByRef resultParamter As ResultParameters)

If I understood correctly I should be able to use ResultParameters to determine the information such as solutionResult, Load case, iteration, etc. I have reached the limit of my programming skills as I not sure how to proceed with the function

Dim iViewID As Integer
Dim iarrTheViewIDs() As Integer
iarrTheViewIDs=theSession.Post.GetPostViewIds
iViewID = iarrTheViewIDs(0)

Dim theresult As CAE.Result
Dim theresultparameters As CAE.ResultParameters
CAE.Post.GetResultForPostview(iViewID,theresult,theresultparameters)

Getting the view ID works !

Perhaps the following code will get you started.

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workSimPart As CAE.CaePart = CType(theSession.Parts.BaseWork, CAE.CaePart)
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim iViewID As Integer
Dim iarrTheViewIDs() As Integer
iarrTheViewIDs = theSession.Post.GetPostviewIds
iViewID = iarrTheViewIDs(0)

lw.WriteLine("number of post view ID's: " & iarrTheViewIDs.Length.ToString)
For Each id As Integer In iarrTheViewIDs
lw.WriteLine(" ID: " & id.ToString)
Next
lw.WriteLine("")

Dim theresult As CAE.Result
Dim theresultparameters As CAE.ResultParameters
theSession.Post.GetResultForPostview(iViewID, theresult, theresultparameters)

lw.WriteLine("Result Name: " & theresult.Name)
lw.WriteLine("number of loadcases: " & theresult.AskNumLoadcases.ToString)
lw.WriteLine("")

'get loadcases
Dim theLoadCases() As CAE.BaseLoadcase
theLoadCases = theresult.GetLoadcases
lw.WriteLine("Load Cases")
lw.WriteLine("-----------------------------------------------------")
Dim loadIndex As Integer = 0
Dim iterationIndex As Integer = 0
For Each tempLoadCase As CAE.Loadcase In theLoadCases
Dim loadDesc As String
Dim loadValue As Double
theresult.AskResultLoadcaseValue(loadIndex, loadDesc, loadValue)
lw.WriteLine("Name: " & tempLoadCase.Name)
lw.WriteLine("Label: " & tempLoadCase.Label)
lw.WriteLine("Description: " & loadDesc)
lw.WriteLine("Value: " & loadValue.ToString)
lw.WriteLine("")
lw.WriteLine("Iterations: [" & (iterationIndex + 1).ToString & " of " & theresult.AskNumIterations(loadIndex).ToString & "]")

Dim lcIterations() As CAE.BaseIteration = tempLoadCase.GetIterations
For Each tempIteration As CAE.Iteration In lcIterations
Dim types() As CAE.Result.Type
Dim desc() As String
theresult.AskResultTypes(loadIndex, iterationIndex, types, desc)
lw.WriteLine(" name: " & tempIteration.Name)
lw.WriteLine(" label: " & tempIteration.Label)
lw.WriteLine(" type: " & tempIteration.Type.ToString)
lw.WriteLine(" value type: " & tempIteration.ValueType.ToString)
lw.WriteLine("")

lw.WriteLine(" Available result types:")
For i As Integer = 0 To types.Length - 1
lw.WriteLine(" quantity: " & types(i).Quantity.ToString)
lw.WriteLine(" location: " & types(i).Location.ToString)
'lw.WriteLine(" section: " & types(i).Section.ToString)
lw.WriteLine("")

Next
lw.WriteLine("")

iterationIndex += 1
Next

loadIndex += 1
Next
lw.WriteLine("-----------------------------------------------------")

lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Thanks a lot for that. I must admit I would have struggle with some of the code
It looks like I was missing 'theSession' on the line Post.GetResultForPostview(iViewID, theresult, theresultparameters). So not a very good start of my part.
Will have to go through the doc to figure out which result, say 'Stress - Element-Nodal, Unaveraged, Von-Mises', is actually posted (in the screen by the user)

Long week-end ahead!

Thanks

Regards

JXB

Thanks
Regards