' ---------------------------------------------- ' ---------------------------------------------- ' NX Activate Sub Directory Search Macro ' ' This macro activates all SubDir Search switches ' for all directories, listed in the Load Options. ' This macro should be used in native NX only ' ' Last Update: 12th November 2011 for ' NX 7.5 ' ' GEA Farm Technologies GmbH ' 100151 CAE/TDM - Matthias Ahrens ' ---------------------------------------------- ' ---------------------------------------------- Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF ' ---------------------------------------------- ' The Module Definition ' ---------------------------------------------- Module NXJournal ' ---------------------------------------------- ' Declare module wide variables ' ---------------------------------------------- ' ---- variable for error codes of internal sub functions ----- Dim errcode As Integer ' ---- variable for reporting of internal sub functions ----- Dim reportlevel As Integer ' ---- variable to control dialog messages ----- Dim Messages As Boolean ' ---- object to access current NX session ----- Dim theSession As Session ' ---- variable to check Teamcenter Mode ----- Dim checkNXManager As Boolean ' ---- arrays of directories and SubDir search flags ----- Dim searchDirectories() As String Dim searchSubDirsFlag() As Boolean ' ---------------------------------------------- ' The major routine, started ' ---------------------------------------------- Sub Main ' ---------------------------------------------- ' Connect the current NX session ' ---------------------------------------------- theSession = Session.GetSession() ' ---------------------------------------------- ' Open report window if required ' ---------------------------------------------- theSession.ListingWindow.Open() ' ---------------------------------------------- ' Call sub function to setup initial values ' ---------------------------------------------- errcode = setup() If reportlevel > 5 Then theSession.ListingWindow.WriteLine("Function errcode: setup() = " & errcode) ' ---------------------------------------------- ' Call sub function to check if system is in TC NX Manager mode ' ---------------------------------------------- errcode = chkNXManager() If reportlevel > 5 Then theSession.ListingWindow.WriteLine("Function errcode: chkNXManager() = " & errcode) If checkNXManager = true Then If Messages = True Then MsgBox("Unable to proceed! You are in Teamcenter Engineering mode!", MsgBoxStyle.Exclamation) GoTo finalized End If ' ---------------------------------------------- ' Get current LoadOptions Directories and Flags ' ---------------------------------------------- theSession.Parts.LoadOptions.GetSearchDirectories(searchDirectories,searchSubDirsFlag) ' ---------------------------------------------- ' Process each entry in the array and set flag to true ' ---------------------------------------------- Dim DirIDX as integer for DirIDX = 0 to Ubound(searchSubDirsFlag) If reportlevel > 5 Then theSession.ListingWindow.WriteLine(" : Search Sub Dir Flag was " & searchSubDirsFlag(DirIDX) & " for dir:" & searchDirectories(DirIDX)) searchSubDirsFlag(DirIDX) = True next DirIDX ' ---------------------------------------------- ' Save modification back to current LoadOptions ' ---------------------------------------------- theSession.Parts.LoadOptions.SetSearchDirectories(searchDirectories,searchSubDirsFlag) ' ---------------------------------------------- ' close window if normal end ' ---------------------------------------------- theSession.ListingWindow.close() ' ---------------------------------------------- ' Entry point for errors or ending the macro ' ---------------------------------------------- finalized: End Sub ' ------------------------------------------------------------------------------------------------------------ ' This sub function is called to check if session is in NX Manager / Teamcenter mode ' ------------------------------------------------------------------------------------------------------------ Function chkNXManager() As Integer Try ' ---------------------------------------------- ' this application makes only sense in TCE NX Manager mode ' ---------------------------------------------- Dim theSession As Session theSession = Session.GetSession() Dim ufs As UFSession ufs = UFSession.GetUFSession() ufs.UF.IsUgmanagerActive(checkNXManager) If reportlevel > 1 Then theSession.ListingWindow.WriteLine("Function : chkNXManager() - checkNXManager = " & checkNXManager) ' ---------------------------------------------- ' provide return errorcode ' ---------------------------------------------- chkNXManager = 0 Catch ex As Exception chkNXManager = 1 End Try End Function ' ------------------------------------------------------------------------------------------------------------ ' This sub function is called to setup intial values ' ------------------------------------------------------------------------------------------------------------ Function setup() As Integer Try ' ------------------------------------------------ ' initial environment setup ' ------------------------------------------------ ' Let us assume that this macro is run without TC Mode checkNXManager=false ' ---------------------------------------------- ' Set report level of script ' ---------------------------------------------- reportlevel = 10 ' 0 = No reports ' 10 = fully detailed reports ' ---------------------------------------------- ' Messages should appear ' ---------------------------------------------- Messages = True ' ---------------------------------------------- ' provide return code ' ---------------------------------------------- setup = 0 Catch ex As NXException setup = 1 End Try End Function End Module