Forums:
I have a journal written that when run will ask the user to input a layer number and then delete all objects from that layer (based on code from this site). The journal works fine in a single assembly. The problem I am running into is when I run the journal in a file with multiple sub-assemblies it will only delete objects from the layer in the top most level (Objects on the selected layer in subs are not deleted). Any suggestions?
Option Strict Off Imports System Imports NXOpen Imports NXOpenUI Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim displayPart As Part = theSession.Parts.Display Dim theUISession As UI = UI.GetUI Dim answer As String = "" Dim myInt As Integer Do answer = NXInputBox.GetInputString("Enter a layer number", "Layer To Be Deleted?", " ") 'if cancel is pressed, exit sub If answer = "" Then Exit Sub Loop Until Integer.TryParse(answer, myInt) theUISession.NXMessageBox.Show("Delete From Layer", NXMessageBox.DialogType.Information, "All objects will be deleted from layer: " & myInt.ToString) '&&&&& layer number to delete objects from Dim layerToDelete As Integer = myInt 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 nErrs1 As Integer nErrs1 = theSession.UpdateManager.AddToDeleteList(workPart.Layers.GetAllObjectsOnLayer(layerToDelete)) Dim nErrs2 As Integer nErrs2 = theSession.UpdateManager.DoUpdate(markId1) End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination End Function End Module