Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module delete_all_objects_on_specified_layer
Public theSession As Session = Session.GetSession()
Public theUFSession As UFSession = UFSession.GetUFSession()
Sub Main()
Dim layerNum As Integer = 0
Dim userInputNumber As Double
userInputNumber = NXInputBox.GetInputNumber("Layer to wipe clean:")
layerNum = userInputNumber
If layerNum < 1 Or layerNum > 256 Then
MsgBox("That is not a valid layer.", MsgBoxStyle.Information)
Return
End If
Dim dispPart As Part = theSession.Parts.Display
Dim objs() As NXObject = dispPart.Layers.GetAllObjectsOnLayer(layerNum)
Dim toDelete As System.Collections.ArrayList = New System.Collections.ArrayList
For Each obj As NXObject In objs
Dim theType As Integer
Dim theSubtype As Integer
theUFSession.Obj.AskTypeAndSubtype(obj.Tag, theType, theSubtype)
If (Not theType = UFConstants.UF_parametric_text_type) And
((Not theType = UFConstants.UF_tabular_note_type) Or _
(theSubtype = UFConstants.UF_tabular_note_section_subtype)) Then
toDelete.Add(obj)
End If
Next
theSession.Information.DisplayObjectsDetails(toDelete.ToArray(GetType(NXObject)))
If AskYesOrNo("Check Information Listing", "Delete all of these objects?") Then
Dim undoMark As Session.UndoMarkId =
theSession.SetUndoMark(Session.MarkVisibility.Visible,
"Delete objects on layer " & layerNum)
theSession.UpdateManager.AddToDeleteList(toDelete.ToArray(GetType(NXObject)))
theSession.UpdateManager.DoUpdate(undoMark)
End If
End Sub
Function AskYesOrNo(ByVal title As String, ByVal message As String) As Boolean
Dim messages As String() = {message}
Dim buttons As UFUi.MessageButtons
With buttons
.button1 = True
.button2 = False
.button3 = True
.label1 = "Yes"
.label2 = Nothing
.label3 = "No"
.response1 = 1
.response2 = 0
.response3 = 2
End With
Dim resp As Integer
theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
theUFSession.Ui.MessageDialog(title, UiMessageDialogType.UiMessageQuestion, messages, 1, True, buttons, resp)
theUFSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
If resp = 1 Then Return True Else Return False
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module