'NXJournaling.com
'June 23, 2016
'Return first layer category found of a given layer number
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module3
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
lw.Open()
Dim layerCat As String = GetLayerCategory(theSession.Parts.Work.Layers.WorkLayer)
If IsNothing(layerCat) Then
lw.WriteLine("layer does not belong to any category")
Else
lw.WriteLine("layer belongs to category: " & layerCat)
End If
lw.Close()
End Sub
Function GetLayerCategory(ByVal layerNum As Integer) As String
'layerNum must be between 1 and 256 inclusive
If layerNum < 1 OrElse layerNum > 256 Then
Return Nothing
End If
For Each temp As Layer.Category In workPart.LayerCategories
If temp.Name = "ALL" Then
'skip the ALL category
Continue For
End If
For Each categoryLayerNum As Integer In temp.GetMemberLayers
If categoryLayerNum = layerNum Then
Return temp.Name
End If
Next
Next
'layer number not found in the existing categories
Return Nothing
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module