Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Delete all layer categories on part

Hi all,

 

How can be customised a VB macro, for deleting all layers categories on a NX part?

 

Thanks.

2 REPLIES

Re: Delete all layer categories on part

[ Edited ]

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

 

Solution
Solution
Accepted by topic author Igor
‎08-26-2015 04:32 AM

Re: Delete all layer categories on part

[ Edited ]

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

 

SteveA
DRT Mfg. Co. Inc.
www.drtusa.com
Win7x64 NX8.5.3.3