Position over ride components in Assembly

Hi,

I am trying to position over ride the components in Assembly Level for arrangement requirements. Initially I am removing position override in all components inside the assembly, Then I override the components only in component groups. I am getting error "A dimension subscript for an array attribute was out of range or invalid". Also it corrupts the part. After this most NX commands throwing the same error. I have to close the session without saving the part to clear this issue. A little guidance would be helpful.

Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Collections
Imports System.Runtime.InteropServices
Imports NXOpen
Imports NXOpen.GeometricUtilities
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpenUI
Imports System.Collections.Generic
Imports System.Threading

Module PositionOverRide

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theUI As UI = UI.GetUI
Dim ufs As UFSession = UFSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

'Remove Position Override for all assembly components
Dim Mycomponent As ComponentAssembly = workPart.ComponentAssembly
RemovePositionOverride(Mycomponent.RootComponent, 0)

'ArrangementOptions.IndividuallyPositioned and Position override for each assemblies
Dim MyCompList As List(Of Component) = New List(Of Component)
For Each compGroup As ComponentGroup In workPart.ComponentGroups
For Each Mycomp As Component In compGroup.GetComponents
MyCompList.Add(Mycomp)
Next
Next
lw.WriteLine(MyCompList.Count)

For Each Mycomp As Component In MyCompList
Try
Dim nullAssemblies_Component As Assemblies.Component = Nothing
Mycomp.EstablishPositionOverride(nullAssemblies_Component)
Dim MyObj(0) As NXObject
MyObj(0) = Mycomp
Dim assembliesParameterPropertiesBuilder1 As AssembliesParameterPropertiesBuilder = workPart.PropertiesManager.CreateAssembliesParameterPropertiesBuilder(MyObj)
assembliesParameterPropertiesBuilder1.Arrangements = Assemblies.AssembliesParameterPropertiesBuilder.ArrangementOptions.IndividuallyPositioned
Dim NxObject1 As NXObject
NxObject1 = assembliesParameterPropertiesBuilder1.Commit()
assembliesParameterPropertiesBuilder1.Destroy()

Catch ex As NXException
lw.WriteLine(ex.ErrorCode & " : " & ex.Message)
End Try
Next

End Sub

Sub RemovePositionOverride(ByVal comp As Component, ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
If child.GetChildren.Length <> 0 Then
Try
Dim nullAssemblies_Component As Assemblies.Component = Nothing
child.RemovePositionOverride(nullAssemblies_Component)
Catch ex As NXException

End Try
Else
Try
Dim nullAssemblies_Component As Assemblies.Component = Nothing
child.RemovePositionOverride(nullAssemblies_Component)
Catch ex As NXException
End Try
End If
RemovePositionOverride(child, indent + 1)
Next
End Sub

End Module