This should do it:
Option Strict Off Imports System Imports NXOpen Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() If IsNothing(theSession.Parts.Work) Then 'active part required Return End If Dim workPart As Part = theSession.Parts.Work Const undoMarkName As String = "delete all layer categories" Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName) Dim nErrs1 As Integer nErrs1 = theSession.UpdateManager.AddToDeleteList(workPart.LayerCategories.ToArray) Dim nErrs2 As Integer nErrs2 = theSession.UpdateManager.DoUpdate(markId1) End Sub End Module
Oops, when I started replying to O.P. there were no other replies. After posting I saw that Cowski1 had already replied. I would suggest using his code - as it checks for a part before proceeding and is more efficient (with the toArray() inside the call [avoiding the loop for adding the catagories to the delete list]).
This is not a Macro - it is a journal.
This was tested in NX8.5 Native
After saving the attached file - in NX Menus - got to Tools->Journal->PLay
Choose the file
There is a commented line in the file:
' MsgBox("Finished: Please click [OK ] button and check Layer-Category results", vbOKOnly, "Information:")
If you remove the leading semicolon - a message box will display when the journal has finished running.
Option Strict Off Imports System Imports NXOpen Module NXJournal Sub Main Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work() Dim myCats() As Layer.Category = workPart.LayerCategories.ToArray() For Each thisCat As Layer.Category In myCats theSession.UpdateManager.AddToDeleteList(thisCat) Next Dim myUndoMark As Session.UndoMarkId = _ theSession.SetUndoMark(Session.MarkVisibility.Invisible, "BeforeUndo") theSession.UpdateManager.DoUpdate(myUndoMark) ' MsgBox("Finished: Please click [OK ] button and check Layer-Category results", vbOKOnly, "Information:") End Sub End Module