Below Journal work fine but it is not deleting the table in layer 256

Option Strict Off
Imports System
Imports NXOpen

Module Module16

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

'layer number to delete objects from
Const layerToDelete As Integer = 256

If displayPart Is Nothing Then
'no part to work on
Exit Sub
End If

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")

Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete

theSession.UpdateManager.ClearErrorList()

Dim V As Integer
V = theSession.UpdateManager.AddToDeleteList(workPart.Layers.GetAllObjectsOnLayer(layerToDelete))

Dim P As Integer
P = theSession.UpdateManager.DoUpdate(markId1)

End Sub
End Module

I created a test file with a 2x2 tabular note (2 rows, 2 columns) and ran your code. It deleted 1 column of the tabular note, but not the entire thing. All other objects on layer 256 were deleted as expected. I suspect that this is not the intended behavior and I would suggest opening a ticket with GTAC (or your local VAR).

In the meantime, I've rewritten the code to delete all the tables first and then look for other objects to delete. In my limited testing, it seems to work well.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module208

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession

Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()
lw.Open()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

'layer number to delete objects from
Const layerToDelete As Integer = 256

If displayPart Is Nothing Then
'no part to work on
Exit Sub
End If

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")

Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete

theSession.UpdateManager.ClearErrorList()

Dim objsToDelete As New List(Of NXObject)
For Each myobj As NXObject In theSession.Parts.Work.Layers.GetAllObjectsOnLayer(layerToDelete)

'lw.WriteLine("object type: " & myobj.GetType.ToString)
If TypeOf (myobj) Is Annotations.Table Then
objsToDelete.Add(myobj)
End If

Next

Dim V As Integer
V = theSession.UpdateManager.AddToDeleteList(objsToDelete.ToArray)

Dim P As Integer
P = theSession.UpdateManager.DoUpdate(markId1)

V = theSession.UpdateManager.AddToDeleteList(workPart.Layers.GetAllObjectsOnLayer(layerToDelete))

P = theSession.UpdateManager.DoUpdate(markId1)

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Hi,

Thanks for the code and it works fine.
the only question is that we don't have any NX open license.
we are just recording journal and using that file.
can we use this file in our organization?

The basic modeling license includes the ability to record, modify, and run journals. You are free to use the code above as you see fit, either on its own or modified as part of a larger journal.

I do not currently have access to an NX open license; fortunately, you can do quite a bit with journals before you run into limitations. One goal of this site is to share code that can be used by someone with only a basic modeling license.

Hi,
Thanks, doubt I am having because of NXOpen.UF
because usually when we record the session it's start with
Import system
Import NXopen

sorry if I am asking too many questions because I am totally new to NX open.
I want to learn and want to be expert.

I copied & pasted your code into one of my templates, this particular journal doesn't use any of the UF functions, so the imports NXOpen.UF line can be deleted.

However, the UF functions are perfectly fine to use in journal code. Sometimes the UF provides functionality that isn't (yet) covered by the .net NXOpen object model. For instance, if you are creating and editing tabular notes, you will probably have to use UF functions.

Hi,
I am discussing about code you shared.
in that NXopen.uf is used
and if I removed that line error comes.

Line 9 : Type 'UFSession' is not defined.
Line 48 : Warning: 'Public Function AddToDeleteList(objects() As NXOpen.NXObject) As Integer' is obsolete: 'Deprecated in NX12.0.0. Use Update.AddObjectsToDeleteList instead.'.
Line 53 : Warning: 'Public Function AddToDeleteList(objects() As NXOpen.NXObject) As Integer' is obsolete: 'Deprecated in NX12.0.0. Use Update.AddObjectsToDeleteList instead.'.

My code declares a variable named "theUfSession" (after the module declaration and before Sub Main). It is never used and can be deleted along with the imports NXOpen.UF statement.