Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "delete unused planes"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim planesToDelete As New List(Of Plane)
For Each tempPlane As Plane In workPart.Planes
Dim featTag As Tag = Tag.Null
theUfSession.Modl.AskObjectFeat(tempPlane.Tag, featTag)
If featTag = Tag.Null Then
planesToDelete.Add(tempPlane)
End If
Next
Dim markId2 As Session.UndoMarkId
[highlight #FCE94F]markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete")[/highlight]
Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
theSession.UpdateManager.ClearErrorList()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(planesToDelete.ToArray)
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)
lw.Close()
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
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module2
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim lg As LogFile = theSession.LogFile
Sub Main()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Const undoMarkName As String = "delete unused planes"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim planesToDelete As New List(Of Plane)
For Each tempPlane As Plane In workPart.Planes
Dim tempFile As String = IO.Path.GetTempFileName
lg.WriteLine("tempFile: " & tempFile)
lw.SelectDevice(ListingWindow.DeviceType.File, tempFile)
lw.Open()
theSession.Information.DisplayObjectsDetails({tempPlane})
lw.Close()
lw.SelectDevice(ListingWindow.DeviceType.Window, "")
If Not IsUsed(tempFile) Then
planesToDelete.Add(tempPlane)
End If
IO.File.Delete(tempFile)
Next
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete")
Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
theSession.UpdateManager.ClearErrorList()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(planesToDelete.ToArray)
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)
End Sub
Function IsUsed(ByVal theFile As String) As Boolean
If Not IO.File.Exists(theFile) Then
Throw New System.IO.FileNotFoundException
lg.WriteLine("Error: file not found")
'assume it is used so it is not marked for deletion
Return True
End If
Dim line As String
Dim checkNextLine As Boolean = False
Dim usedBy As String
Using sr As IO.StreamReader = New IO.StreamReader(theFile)
Try
line = sr.ReadLine()
While Not line Is Nothing
If checkNextLine Then
usedBy = line
lg.WriteLine("used by: " & usedBy)
If usedBy.Trim.ToLower = "none" Then
lg.WriteLine("Function 'IsUsed' returning: False")
Return False
Else
lg.WriteLine("Function 'IsUsed' returning: True")
Return True
End If
End If
If line = "Used by:" Then
checkNextLine = True
lg.WriteLine("line: 'Used by:' found")
End If
line = sr.ReadLine()
End While
Catch E As Exception
End Try
End Using
End Function
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