Delete Curve by Name in NX 11

Hello,

I am trying to delete curve by searching its name.
I have used below code and it is working in NX 9 and NX 10 but it is not working in NX 11.
Can anyone please help me to find my mistake ?

Sub Main

theSession = Session.GetSession()
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
Dim Curves As CurveCollection = workPart.Curves
Dim bodyname As String = Line

For Each oCurve As Curve In Curves

If oCurve.Name = bodyname Then

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Delete")
Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
theSession.UpdateManager.ClearErrorList()

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(oCurve)

Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)
theSession.DeleteUndoMark(markId1, Nothing)

End If
Next
End Sub

It is not recommended to delete members of the collection while you are iterating through the collection; this can result in items of the collection inadvertently being deleted or skipped. I suggest iterating through the collection, adding each item you want to delete to a list. When you are done working through the list, delete the items you have collected. The code in the following thread shows one way to do this
http://nxjournaling.com/comment/362#comment-362
This code is looking for items on a specific layer rather than items with a specific name, but the strategy of collecting them then deleting them is the same.

Hello,

Thanks for improving me.
I found one more solution in this case.

When we create any vbproject we need to reference NXOpen.dll files.
If I referenced NX11 dll path so same code is not working in NX9 and NX10 but works in NX11.
Path is for NX11 : "NX11.0\NXBIN\managed"
and for NX9 and NX 10 : "NX9\UGII\managed"

Is there any solution for this?

Bhavik S.

If you are running the code as a journal, NX should run it with no problems - it will compile the code and reference the correct dll files "behind the scenes". If you are compiling your code to a dll file and running it, you will need to reference the correct NX dll files in your project. It is recommended that you recompile the project for each new release of NX.

Hi

Thanks for the information.

Bhavik S.