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.
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
Solved! Go to Solution.
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 innacessible due ot its pretecitn level'
'solution2' is definitly declared, see code below.
any idea why 'solution2' declaratin is creating such problem?
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
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).
Thanks foe the clarification cowski1. Much appreciated.
Do you know if there is a option 'List Results'? There is nothing obvious in the doc (Results section).If one has a (peak) result in an NX response simulation, by right-clicking one gets the info on that result, see example below;
Information listing created by : a.guy
Date : 14/04/2015 00:00:00
Current work part : C:\mytest_createpeak.sim
Node name : abcd123456
Peak Element Force_X:
Coordinate System: Elemental
Node 325133: 5.996e+005
Node 320704: -5.996e+005
Node 325134: 3.813e+005
Node 320705: -3.813e+005
As I now have a programme which can create the results required and can loop through the results, I'd like to "list the results" and then using the listing window write to file (and window):
I vaguely rembered askign a very simialr question (about the 'List Results')
and was pointed toward DisplayObjectsDetails(). Looking at the doc it seems that 'Result' is an NXObject
Has anyone a example on how to use DisplayObjectsDetails() ?