Looping through results of a Response Simulation (event)-How to ?

To all,

I am currently to establish a way of looping through the results in a Response Simulation Event. The idea is to find the last result to extract specific data. In my test case the result I am after is

'Peak Result X'
---Peak Element Force_X
---Peak Element Force_Y
---Peak Element Force_Z

where X is the ID

I have a function, see below, which loops through the results for a Solution but I am struggling to modify it for a Response Simulation (and its events). As a starting point the response simulation (name) and the event (name) entered by the user are known and both exist.

any help or pointer would be grealty appreciated.

Thanks

Regards

JXB

Dim simulation As CAE.SimSimulation = theSimPart.Simulation()
Dim solution As CAE.SimSolution = simulation.ActiveSolution()

Dim results As CAE.Result = GetResults(solution2)
Dim nLoadCases As Integer = results.AskNumLoadcases()

theLW.Open()
theLW.WriteLine("" + "Solution [" + solution.Name + "] has " + nLoadCases.ToString + " LoadCases ")

For iLoadCase As Integer = 0 To nLoadCases-1

Dim nIterations As Integer = results.AskNumIterations(iLoadCase)

theLW.WriteLine(" " + "LoadCase [" + iLoadCase.ToString + "] has " + nIterations.ToString + " Iterations ")

For iIterations As Integer = 0 To nIterations-1
Dim resultTypes() As CAE.Result.Type
Dim resultTypeDescription() As String
results.AskResultTypes(iLoadCase, iIterations, resultTypes, resultTypeDescription)
Dim nTypes = resultTypes.Length

theLW.WriteLine(" " + "Iteration [" + iIterations.ToString + "] has " + nTypes.ToString + " Result Types ")

For iType As Integer = 0 To nTypes-1
theLW.WriteLine(" " + "result type [" + iType.ToString() + "]: " + resultTypeDescription(iType ))

Next

Next

Next
Function GetResults(ByRef solution As CAE.SimSolution) As CAE.Result
'Function GetResults(ByRef solution As CAE.ResponseSimulation.Solution) As CAE.Result

Function GetResults(ByRef solution As CAE.SimSolution) As CAE.Result

Dim results As CAE.Result = Nothing
Dim part As BasePart = theSession.Parts.BaseWork
Dim theResultManager As CAE.ResultManager = theSession.ResultManager()

If (theResultManager Is Nothing) Then
theNXMessageBox.Show("Test", NXMessageBox.DialogType.Error, "No valid ResultManager")
Return Nothing
End If

Dim solresults As CAE.SolutionResult = Nothing

Try

solresults = theResultManager.CreateSolutionResult(solution)

Catch ex As Exception
Return Nothing
End Try

If (solresults Is Nothing) Then
theNXMessageBox.Show("Test", NXMessageBox.DialogType.Error, "Could not Access Solution Results")
Return Nothing
End If

results = CType(solresults, CAE.Result)

Return results

End Function

did a bit of reading and found that the resp. simulation results may have to be accessed using CreateResponseEventResult(RSEvent). I therefore need to pass the RSEvent As CAE.ResponseSimulation.RSEvent to the function GetResult()

1st test failed because I get an error message about the:

'solution2' not being declared. It may be inaccessible due to its protection level'
'solution2' is definitely declared, see code below.

any idea why 'solution2' declaration is creating such problem?

Thansk

Regards

Try

Dim solution2 As CAE.ResponseSimulation.Solution = CType(workSimPart.Simulation.ResponseSimulationManager.Solutions.FindObject(sRespSimSolName), CAE.ResponseSimulation.Solution)

Dim RSEvent2 As CAE.ResponseSimulation.RSEvent = CType(solution2.FindObject(sRSEventName), CAE.ResponseSimulation.RSEvent)

solution2.ActiveEvent = RSEvent2

peakValueEvaluationSetting1 = CType(nXObject1, CAE.ResponseSimulation.PeakValueEvaluationSetting)

theSession.Post.UnloadResultFile(pathRS2File)
RSEvent2.EvaluatePeakValueResults(peakValueEvaluationSetting1)

peakValueEvaluationSetting1.Destroy()peakValueEvaluationSettingBuilder1.Destroy()

Catch ex As Exception
iError += 1
'---- Enter your exception handling code here -----
'Throw ex
End Try

Thanks
Regards

When you get a "It may be inaccessible due to its protection level" warning/error, it usually has to do with the "scope" of the variable, which is determined by where it is declared. In your specific case, the variable is declared within the "Try" portion of the Try Catch block. The "lifetime" of the variable ends when the Try portion of the block ends; the variable will only be available to your program within the Try block. There are good reasons to limit the scope of variables like this; it is best practice to only use variables as long as needed and no longer within the program (this will avoid other code changing the value of your variables when you are not looking!).

I see from your most recent message that you moved the declaration of the variable outside of the Try block. The variable will now have a "scope" defined by the new container (sub/function, block, class, etc).

not sure why the original variable declaration didn't work but I slightly modified the code by defining the variables
Dim theActiveRespSim As CAE.ResponseSimulation.Solution
Dim theActiveRSEvent As CAE.ResponseSimulation.RSEvent
just before the TRy ...Cathc loop and it seems to work

Accessing the results in the Resp. sim. Event of interest was indeed via
theResultManager.CreateResponseEventResult(theRSEvent)

Regards

JXB

Thanks
Regards

to all

the function I have coded returns the result (Dim results As CAE.Result) for a specific resp. simulation event. I know I can get the load case ID using
Dim iLoadCase As Integer = results.AskNumLoadcases()

but I am only interested in the last load case (as it is the one just created by the program). I have a loop which loops (!) through all the load cases), see below, to extract the data. I am looking for a way of specifying a specific load case. Is there a way of doing so?

For Each loadcase As CAE.BaseLoadcase In results.GetLoadcases
' Loop through all iterations in the loadcase
For Each iteration As CAE.BaseIteration In loadcase.GetIterations
For Each baseResultType As CAE.BaseResultType In iteration.GetResultTypes
Next baseResultType
Next iteration
Next loadcase

Thanks
Regards

The .AskNumLoadcases method tells us how many load cases there are; .GetLoadcases returns an array of all the load cases. We can combine their power to get access to the last load case:


Dim lastLoadCase As CAE.BaseLoadcase
lastLoadCase = results.getloadcases(results.AskNumLoadcases - 1)

We subtract one from the number of load cases because arrays are zero based. If .AskNumLoadcases tells us there are 5 load cases, that means the array indices range from zero to four.

Thanks a lot for that NXJournaling. Muc appreciated. I am getting close to looping through the last load case and extracting the X,Y and Z Force for a list of FE Element. Some minor problems on the looping but will get there

Dim lastLoadCase As CAE.BaseLoadcase
lastLoadCase = results.getloadcases(results.AskNumLoadcases - 1)

For Each iteration As CAE.BaseIteration In lastLoadCase.GetIterations
Next iteration

Thanks
Regards