table of results

Hi everyone !

I would like to create a table in a journal that contain all the displacement and stresses of each elements of my part.
I have managed to create a table with the displacement but when I when to put stresses like Xx or Von Mises the program fail.

there is my code :

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.BlockStyler

Module Module2

Dim theSession As Session = Session.GetSession()
Dim theLW As NXOpen.ListingWindow = theSession.ListingWindow()
Dim theUI As NXOpen.UI = NXOpen.UI.GetUI()
Dim theNXMessageBox As NXMessageBox = theUI.NXMessageBox

Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theLW As NXOpen.ListingWindow
theLW = theSession.ListingWindow()

theLW.Open()
Doit()

End Sub

Sub Doit()

Dim nom_loadcase As String
Dim resultParameters1 As CAE.ResultParameters
Dim theSession As Session = Session.GetSession()
Dim resultManager1 As CAE.ResultManager = theSession.ResultManager
Dim simPart As CAE.SimPart = CType(theSession.Parts.BaseWork, CAE.SimPart)
Dim simulation As CAE.SimSimulation = simPart.Simulation()
Dim workSimPart As CAE.SimPart = CType(theSession.Parts.BaseWork, CAE.SimPart)
Dim solution As CAE.SimSolution = simulation.ActiveSolution()
Dim resultType As CAE.Result.Type
Dim results As CAE.Result = GetResults(solution ) 'appel de la fonction GetResults

Dim scale As Double = 1.0
Dim loadCaseIdx As Integer = 0
Dim iterationIdx As Integer = 0
Dim resultAccess As CAE.ResultAccess = GetResultAccess(results, loadCaseIdx, iterationIdx, scale) 'appel de la fonction GetResultsAccess
Dim resultAccess2 As CAE.ResultAccess = GetResultAccess2(results, loadCaseIdx, iterationIdx, scale)
Dim resultAccess3 As CAE.ResultAccess = GetResultAccess3(results, loadCaseIdx, iterationIdx, scale)
Dim resultAccess4 As CAE.ResultAccess = GetResultAccess4(results, loadCaseIdx, iterationIdx, scale)
Dim resultAccess5 As CAE.ResultAccess = GetResultAccess5(results, resultType, loadCaseIdx, iterationIdx, scale)

Dim n As Integer
'Dim Table(8044,4) As Double
Dim Table(8044,4) As Object
Dim h,i,j,k,l As Double

For n=1 to 8044

h = resultAccess.AskNodalResult(n)
i = resultAccess2.AskNodalResult(n)
j = resultAccess3.AskNodalResult(n)
k = resultAccess4.AskNodalResult(n)
l = resultAccess5.AskElementResult(n)

Table(n,1)=h
Table(n,2)=i
Table(n,3)=j
Table(n,4)=k
Table(n,5)=l

next n

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

lw.WriteLine(Table(8044,4))

End Sub

'***************************************************************fonction décplacement Nodal Magnitude***************************************************

Function GetResultAccess(ByRef results As CAE.Result, ByVal loadCaseIdx As Integer, ByVal iterationIdx As Integer, ByVal scale As Double) As CAE.ResultAccess

Dim part As BasePart = theSession.Parts.BaseWork
Dim theResultManager As CAE.ResultManager = theSession.ResultManager()
Dim unit_length As Unit = Nothing
Dim resultParameter As CAE.ResultParameters = theResultManager.CreateResultParameters()
Dim resultType As CAE.Result.Type

' Dim averaging As CAE.Result.Averaging
' averaging.DoAveraging = False
' averaging.AverageAcrossPropertyIds = True
' averaging.AverageAcrossMaterialIds = True
' averaging.AverageAcrossElementTypes = True
' averaging.AverageAcrossFeatangle = True
' averaging.AverageAcrossAnglevalue = 45.0
' averaging.IncludeInternalElementContributions = True

resultParameter.SetLoadcaseIteration(loadCaseIdx, iterationIdx)
resultParameter.SetResultType(resultType)

resultParameter.SetResultComponent(CAE.Result.Component.Magnitude) ' choix du type de résultats

' resultParameter.SetSectionPlyLayer(0, 0, 0)
' resultParameter.SetAveragingCriteria(averaging)
' resultParameter.SetCoordinateSystem(CAE.Result.CoordinateSystem.AbsoluteRectangular)
' resultParameter.SetElementValueCriterion(CAE.Result.ElementValueCriterion.Average)
' resultParameter.SetPhaseAngle(0.0)
' resultParameter.SetScale(scale)
resultParameter.SetUnit(unit_length)
resultParameter.SetComplexCriterion(CAE.Result.Complex.Amplitude)

Dim solResultsAccess As CAE.ResultAccess = theResultManager.CreateResultAccess(results, resultParameter)
solResultsAccess.SetParameters(resultParameter)

Return solResultsAccess

End Function

'***************************************************************fonction décplacement Nodal X ***************************************************

Function GetResultAccess2(ByRef results As CAE.Result, ByVal loadCaseIdx As Integer, ByVal iterationIdx As Integer, ByVal scale As Double) As CAE.ResultAccess

Dim part As BasePart = theSession.Parts.BaseWork
Dim theResultManager As CAE.ResultManager = theSession.ResultManager()
Dim unit_length As Unit = Nothing
Dim resultParameter As CAE.ResultParameters = theResultManager.CreateResultParameters()
Dim resultType As CAE.Result.Type

resultParameter.SetLoadcaseIteration(loadCaseIdx, iterationIdx)
resultParameter.SetResultType(resultType)
resultParameter.SetUnit(unit_length)

resultParameter.SetResultComponent(CAE.Result.Component.X) ' choix du type de résultats

resultParameter.SetComplexCriterion(CAE.Result.Complex.Amplitude)

Dim solResultsAccess As CAE.ResultAccess = theResultManager.CreateResultAccess(results, resultParameter)
solResultsAccess.SetParameters(resultParameter)

Return solResultsAccess

End Function

'***************************************************************fonction décplacement Nodal Y ***************************************************

Function GetResultAccess3(ByRef results As CAE.Result, ByVal loadCaseIdx As Integer, ByVal iterationIdx As Integer, ByVal scale As Double) As CAE.ResultAccess

Dim part As BasePart = theSession.Parts.BaseWork
Dim theResultManager As CAE.ResultManager = theSession.ResultManager()
Dim unit_length As Unit = Nothing
Dim resultParameter As CAE.ResultParameters = theResultManager.CreateResultParameters()
Dim resultType As CAE.Result.Type

resultParameter.SetLoadcaseIteration(loadCaseIdx, iterationIdx)
resultParameter.SetResultType(resultType)
resultParameter.SetUnit(unit_length)

resultParameter.SetResultComponent(CAE.Result.Component.Y) ' choix du type de résultats

resultParameter.SetComplexCriterion(CAE.Result.Complex.Amplitude)

Dim solResultsAccess As CAE.ResultAccess = theResultManager.CreateResultAccess(results, resultParameter)
solResultsAccess.SetParameters(resultParameter)

Return solResultsAccess

End Function

'***************************************************************fonction décplacement Nodal Z ***************************************************

Function GetResultAccess4(ByRef results As CAE.Result, ByVal loadCaseIdx As Integer, ByVal iterationIdx As Integer, ByVal scale As Double) As CAE.ResultAccess

Dim part As BasePart = theSession.Parts.BaseWork
Dim theResultManager As CAE.ResultManager = theSession.ResultManager()
Dim unit_length As Unit = Nothing
Dim resultParameter As CAE.ResultParameters = theResultManager.CreateResultParameters()
Dim resultType As CAE.Result.Type

resultParameter.SetLoadcaseIteration(loadCaseIdx, iterationIdx)
resultParameter.SetResultType(resultType)
resultParameter.SetUnit(unit_length)

resultParameter.SetResultComponent(CAE.Result.Component.Z) ' choix du type de résultats

resultParameter.SetComplexCriterion(CAE.Result.Complex.Amplitude)
Dim solResultsAccess As CAE.ResultAccess = theResultManager.CreateResultAccess(results, resultParameter)
solResultsAccess.SetParameters(resultParameter)

Return solResultsAccess

End Function

'***************************************************************fonction contrainte Xx ***************************************************

Function GetResultAccess5(ByRef results As CAE.Result, ByRef resultType As CAE.Result.Type, ByVal loadCaseIdx As Integer, ByVal iterationIdx As Integer, ByVal scale As Double) As CAE.ResultAccess

Dim part As BasePart = theSession.Parts.BaseWork
Dim theResultManager As CAE.ResultManager = theSession.ResultManager()
Dim unit_stress As Unit = CType(part.UnitCollection.FindObject("MilliNewtonPerSquareMilliMeter"), Unit)
Dim resultParameter As CAE.ResultParameters = theResultManager.CreateResultParameters()

resultType.Quantity = CAE.Result.Quantity.Stress
resultType.Location = CAE.Result.Location.ElementNodal
resultType.Section = CAE.Result.Section.NotApplicable
Dim averaging As CAE.Result.Averaging

averaging.DoAveraging = False
averaging.AverageAcrossPropertyIds = True
averaging.AverageAcrossMaterialIds = True
averaging.AverageAcrossElementTypes = False
averaging.AverageAcrossFeatangle = True
averaging.AverageAcrossAnglevalue = 45.0
averaging.IncludeInternalElementContributions = True

resultParameter.SetLoadcaseIteration(loadCaseIdx, iterationIdx)
resultParameter.SetResultType(resultType)
resultParameter.SetResultComponent(CAE.Result.Component.VonMises)
resultParameter.SetSectionPlyLayer(0, 0, 0)
resultParameter.SetAveragingCriteria(averaging)
resultParameter.SetCoordinateSystem(CAE.Result.CoordinateSystem.AbsoluteRectangular)
resultParameter.SetElementValueCriterion(CAE.Result.ElementValueCriterion.Average)
resultParameter.SetComplexCriterion(CAE.Result.Complex.Real)
resultParameter.SetPhaseAngle(0.0)
resultParameter.SetScale(scale)
'resultParameter.SetUnit = unit_stress
Dim solResultsAccess As CAE.ResultAccess = theResultManager.CreateResultAccess(results, resultParameter)
solResultsAccess.SetParameters(resultParameter)

Return solResultsAccess

End Function

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()
Dim solresults As CAE.SolutionResult = theResultManager.CreateSolutionResult(solution )

results = CType(solresults, CAE.Result)

Return results

End Function

End Module

Thanks for your help

Regards
Ben