NX VB Script to Select CAM Setup Configuration Preference

2024-08-22T11:52:25Z
NX Open NX for Manufacturing

Summary


Details

How to change CAM Setup Configuration Preference?

Solution

You can go to:

Menu->Preferences->Manufacturing->Configuration

Or you can play the following VB Script:

Option Strict Off Imports System Imports System.Collections Imports System.IO Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Module set_cam_cfg_file_preference Dim theSession As Session = Session.GetSession() Dim theUFSession As UFSession = UFSession.GetUFSession() Dim theUI = NXOpen.UI.GetUI Dim wp As Part = theSession.Parts.Work Dim dp As Part = theSession.Parts.Display Public camcfgDir As String = Nothing Public camtplDir As String = Nothing Dim slctdcfgPathFile As String = Nothing Dim tmpltoptPathFile As String = Nothing Dim slctdcfgFile As String = Nothing Dim tmpltoptFile As String = Nothing Dim flist As ArrayList = New ArrayList Sub Main() 'Dim flist As ArrayList = New ArrayList theUFSession.UF.TranslateVariable("UGII_CAM_CONFIG_DIR", camcfgDir) theUFSession.UF.TranslateVariable("UGII_CAM_TEMPLATE_SET_DIR", camtplDir) For Each camdatFile As String In My.Computer.FileSystem.GetFiles(camcfgDir) Dim fullpathFilename As String = Nothing Dim fullpath As String = Nothing Dim filename As String = Nothing Dim extension As String = Nothing fullpathFilename = camdatFile Call ParseFullpathFilename(fullpathFilename, fullpath, filename, extension) flist.Add(filename) Next slctdcfgFile = ChooseOneString("SELECIONE UMA CONFIGURACAO DE CAM", flist) If slctdcfgFile <> "" Then tmpltoptPathFile = camtplDir & slctdcfgFile & ".opt" If System.IO.File.Exists(tmpltoptPathFile) = False Then theUFSession.Ui.DisplayMessage("Arquivo de Template não encontrado * Por favor, verifique!", 1) Exit Sub End If slctdcfgPathFile = camcfgDir & slctdcfgFile & ".dat" tmpltoptFile = slctdcfgFile & ".opt" slctdcfgFile = slctdcfgFile & ".dat" theUFSession.UF.SetVariable("UGII_CAM_CONFIG_FILE", slctdcfgPathFile) theUFSession.UF.SetVariable("UGII_CAM_DEFAULT_TYPE_TEMPLATE", tmpltoptPathFile) Dim preferences1 As NXOpen.CAM.Preferences = Nothing Dim nXObject1 As NXOpen.NXObject = Nothing preferences1 = theSession.CAMSession.CreateCamPreferences() preferences1.ConfigurationFile = slctdcfgPathFile preferences1.TemplateFile = tmpltoptPathFile nXObject1 = preferences1.Commit() preferences1.Destroy() theUI.NXMessageBox.Show("Configuração Selecionada: ", NXOpen.NXMessageBox.DialogType.Information, String.Concat(slctdcfgFile, vbCrLf, tmpltoptFile)) End If End Sub Function ChooseOneString(ByRef prompt As String, ByRef choices As ArrayList) As String If choices.Count() = 1 Then Return choices(0).ToString Dim opts(13) As String Dim a As Integer = 0 Dim ii, resp, z As Integer Dim n_choices As Integer = choices.Count Do If (n_choices - a) < 14 Then z = n_choices - a Else z = 14 End If For ii = 0 To z - 1 opts(ii) = choices(a + ii) Next If ((z = 14) And ((a + z) < n_choices)) Then opts(13) = "More..." theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) resp = theUFSession.Ui.DisplayMenu(prompt, 0, opts, z) theUFSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Select Case resp Case 1 ' Back If (a = 0) Then Return Nothing a = a - 13 Case 2 ' Cancel Return Nothing Case 18 ' More ... If ((a + z) < n_choices) Then a = a + 13 Case Else ' Picked one Return choices(a + resp - 5).ToString End Select Loop While True Return Nothing ' can't really get here End Function Sub ParseFullpathFilename(ByVal fullpathFilename As String, ByRef fullpath As String, ByRef filename As String, ByRef extension As String) Dim i As Integer = Nothing Dim splitFullpathFilename() As String = Nothing Dim filenameAndExtension() As String = Nothing splitFullpathFilename = fullpathFilename.Split("\"c) filenameAndExtension = splitFullpathFilename(splitFullpathFilename.Length - 1).Split("."c) filename = filenameAndExtension(0) extension = filenameAndExtension(filenameAndExtension.Length - 1) fullpath = "" For i = 0 To (splitFullpathFilename.Length - 2) fullpath = fullpath & splitFullpathFilename(i) & "\" Next i End Sub End ModuleOption Strict Off Imports System Imports System.Collections Imports System.IO Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Module set_cam_cfg_file_preference Dim theSession As Session = Session.GetSession() Dim theUFSession As UFSession = UFSession.GetUFSession() Dim theUI = NXOpen.UI.GetUI Dim wp As Part = theSession.Parts.Work Dim dp As Part = theSession.Parts.Display Public camcfgDir As String = Nothing Public camtplDir As String = Nothing Dim slctdcfgPathFile As String = Nothing Dim tmpltoptPathFile As String = Nothing Dim slctdcfgFile As String = Nothing Dim tmpltoptFile As String = Nothing Dim flist As ArrayList = New ArrayList Sub Main() 'Dim flist As ArrayList = New ArrayList theUFSession.UF.TranslateVariable("UGII_CAM_CONFIG_DIR", camcfgDir) theUFSession.UF.TranslateVariable("UGII_CAM_TEMPLATE_SET_DIR", camtplDir) For Each camdatFile As String In My.Computer.FileSystem.GetFiles(camcfgDir) Dim fullpathFilename As String = Nothing Dim fullpath As String = Nothing Dim filename As String = Nothing Dim extension As String = Nothing fullpathFilename = camdatFile Call ParseFullpathFilename(fullpathFilename, fullpath, filename, extension) flist.Add(filename) Next slctdcfgFile = ChooseOneString("SELECIONE UMA CONFIGURACAO DE CAM", flist) If slctdcfgFile <> "" Then tmpltoptPathFile = camtplDir & slctdcfgFile & ".opt" If System.IO.File.Exists(tmpltoptPathFile) = False Then theUFSession.Ui.DisplayMessage("Arquivo de Template não encontrado * Por favor, verifique!", 1) Exit Sub End If slctdcfgPathFile = camcfgDir & slctdcfgFile & ".dat" tmpltoptFile = slctdcfgFile & ".opt" slctdcfgFile = slctdcfgFile & ".dat" theUFSession.UF.SetVariable("UGII_CAM_CONFIG_FILE", slctdcfgPathFile) theUFSession.UF.SetVariable("UGII_CAM_DEFAULT_TYPE_TEMPLATE", tmpltoptPathFile) Dim preferences1 As NXOpen.CAM.Preferences = Nothing Dim nXObject1 As NXOpen.NXObject = Nothing preferences1 = theSession.CAMSession.CreateCamPreferences() preferences1.ConfigurationFile = slctdcfgPathFile preferences1.TemplateFile = tmpltoptPathFile nXObject1 = preferences1.Commit() preferences1.Destroy() theUI.NXMessageBox.Show("Configuração Selecionada: ", NXOpen.NXMessageBox.DialogType.Information, String.Concat(slctdcfgFile, vbCrLf, tmpltoptFile)) End If End Sub Function ChooseOneString(ByRef prompt As String, ByRef choices As ArrayList) As String If choices.Count() = 1 Then Return choices(0).ToString Dim opts(13) As String Dim a As Integer = 0 Dim ii, resp, z As Integer Dim n_choices As Integer = choices.Count Do If (n_choices - a) < 14 Then z = n_choices - a Else z = 14 End If For ii = 0 To z - 1 opts(ii) = choices(a + ii) Next If ((z = 14) And ((a + z) < n_choices)) Then opts(13) = "More..." theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) resp = theUFSession.Ui.DisplayMenu(prompt, 0, opts, z) theUFSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Select Case resp Case 1 ' Back If (a = 0) Then Return Nothing a = a - 13 Case 2 ' Cancel Return Nothing Case 18 ' More ... If ((a + z) < n_choices) Then a = a + 13 Case Else ' Picked one Return choices(a + resp - 5).ToString End Select Loop While True Return Nothing ' can't really get here End Function Sub ParseFullpathFilename(ByVal fullpathFilename As String, ByRef fullpath As String, ByRef filename As String, ByRef extension As String) Dim i As Integer = Nothing Dim splitFullpathFilename() As String = Nothing Dim filenameAndExtension() As String = Nothing splitFullpathFilename = fullpathFilename.Split("\"c) filenameAndExtension = splitFullpathFilename(splitFullpathFilename.Length - 1).Split("."c) filename = filenameAndExtension(0) extension = filenameAndExtension(filenameAndExtension.Length - 1) fullpath = "" For i = 0 To (splitFullpathFilename.Length - 2) fullpath = fullpath & splitFullpathFilename(i) & "\" Next i End Sub End ModuleOption Strict Off Imports System Imports System.Collections Imports System.IO Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Module set_cam_cfg_file_preference Dim theSession As Session = Session.GetSession() Dim theUFSession As UFSession = UFSession.GetUFSession() Dim theUI = NXOpen.UI.GetUI Dim wp As Part = theSession.Parts.Work Dim dp As Part = theSession.Parts.Display Public camcfgDir As String = Nothing Public camtplDir As String = Nothing Dim slctdcfgPathFile As String = Nothing Dim tmpltoptPathFile As String = Nothing Dim slctdcfgFile As String = Nothing Dim tmpltoptFile As String = Nothing Dim flist As ArrayList = New ArrayList Sub Main() 'Dim flist As ArrayList = New ArrayList theUFSession.UF.TranslateVariable("UGII_CAM_CONFIG_DIR", camcfgDir) theUFSession.UF.TranslateVariable("UGII_CAM_TEMPLATE_SET_DIR", camtplDir) For Each camdatFile As String In My.Computer.FileSystem.GetFiles(camcfgDir) Dim fullpathFilename As String = Nothing Dim fullpath As String = Nothing Dim filename As String = Nothing Dim extension As String = Nothing fullpathFilename = camdatFile Call ParseFullpathFilename(fullpathFilename, fullpath, filename, extension) flist.Add(filename) Next slctdcfgFile = ChooseOneString("SELECIONE UMA CONFIGURACAO DE CAM", flist) If slctdcfgFile <> "" Then tmpltoptPathFile = camtplDir & slctdcfgFile & ".opt" If System.IO.File.Exists(tmpltoptPathFile) = False Then theUFSession.Ui.DisplayMessage("Arquivo de Template não encontrado * Por favor, verifique!", 1) Exit Sub End If slctdcfgPathFile = camcfgDir & slctdcfgFile & ".dat" tmpltoptFile = slctdcfgFile & ".opt" slctdcfgFile = slctdcfgFile & ".dat" theUFSession.UF.SetVariable("UGII_CAM_CONFIG_FILE", slctdcfgPathFile) theUFSession.UF.SetVariable("UGII_CAM_DEFAULT_TYPE_TEMPLATE", tmpltoptPathFile) Dim preferences1 As NXOpen.CAM.Preferences = Nothing Dim nXObject1 As NXOpen.NXObject = Nothing preferences1 = theSession.CAMSession.CreateCamPreferences() preferences1.ConfigurationFile = slctdcfgPathFile preferences1.TemplateFile = tmpltoptPathFile nXObject1 = preferences1.Commit() preferences1.Destroy() theUI.NXMessageBox.Show("Configuração Selecionada: ", NXOpen.NXMessageBox.DialogType.Information, String.Concat(slctdcfgFile, vbCrLf, tmpltoptFile)) End If End Sub Function ChooseOneString(ByRef prompt As String, ByRef choices As ArrayList) As String If choices.Count() = 1 Then Return choices(0).ToString Dim opts(13) As String Dim a As Integer = 0 Dim ii, resp, z As Integer Dim n_choices As Integer = choices.Count Do If (n_choices - a) < 14 Then z = n_choices - a Else z = 14 End If For ii = 0 To z - 1 opts(ii) = choices(a + ii) Next If ((z = 14) And ((a + z) < n_choices)) Then opts(13) = "More..." theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) resp = theUFSession.Ui.DisplayMenu(prompt, 0, opts, z) theUFSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Select Case resp Case 1 ' Back If (a = 0) Then Return Nothing a = a - 13 Case 2 ' Cancel Return Nothing Case 18 ' More ... If ((a + z) < n_choices) Then a = a + 13 Case Else ' Picked one Return choices(a + resp - 5).ToString End Select Loop While True Return Nothing ' can't really get here End Function Sub ParseFullpathFilename(ByVal fullpathFilename As String, ByRef fullpath As String, ByRef filename As String, ByRef extension As String) Dim i As Integer = Nothing Dim splitFullpathFilename() As String = Nothing Dim filenameAndExtension() As String = Nothing splitFullpathFilename = fullpathFilename.Split("\"c) filenameAndExtension = splitFullpathFilename(splitFullpathFilename.Length - 1).Split("."c) filename = filenameAndExtension(0) extension = filenameAndExtension(filenameAndExtension.Length - 1) fullpath = "" For i = 0 To (splitFullpathFilename.Length - 2) fullpath = fullpath & splitFullpathFilename(i) & "\" Next i End Sub End ModuleOption Strict Off Imports System Imports System.Collections Imports System.IO Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Module set_cam_cfg_file_preference Dim theSession As Session = Session.GetSession() Dim theUFSession As UFSession = UFSession.GetUFSession() Dim theUI = NXOpen.UI.GetUI Dim wp As Part = theSession.Parts.Work Dim dp As Part = theSession.Parts.Display Public camcfgDir As String = Nothing Public camtplDir As String = Nothing Dim slctdcfgPathFile As String = Nothing Dim tmpltoptPathFile As String = Nothing Dim slctdcfgFile As String = Nothing Dim tmpltoptFile As String = Nothing Dim flist As ArrayList = New ArrayList Sub Main() 'Dim flist As ArrayList = New ArrayList theUFSession.UF.TranslateVariable("UGII_CAM_CONFIG_DIR", camcfgDir) theUFSession.UF.TranslateVariable("UGII_CAM_TEMPLATE_SET_DIR", camtplDir) For Each camdatFile As String In My.Computer.FileSystem.GetFiles(camcfgDir) Dim fullpathFilename As String = Nothing Dim fullpath As String = Nothing Dim filename As String = Nothing Dim extension As String = Nothing fullpathFilename = camdatFile Call ParseFullpathFilename(fullpathFilename, fullpath, filename, extension) flist.Add(filename) Next slctdcfgFile = ChooseOneString("SELECIONE UMA CONFIGURACAO DE CAM", flist) If slctdcfgFile <> "" Then tmpltoptPathFile = camtplDir & slctdcfgFile & ".opt" If System.IO.File.Exists(tmpltoptPathFile) = False Then theUFSession.Ui.DisplayMessage("Arquivo de Template não encontrado * Por favor, verifique!", 1) Exit Sub End If slctdcfgPathFile = camcfgDir & slctdcfgFile & ".dat" tmpltoptFile = slctdcfgFile & ".opt" slctdcfgFile = slctdcfgFile & ".dat" theUFSession.UF.SetVariable("UGII_CAM_CONFIG_FILE", slctdcfgPathFile) theUFSession.UF.SetVariable("UGII_CAM_DEFAULT_TYPE_TEMPLATE", tmpltoptPathFile) Dim preferences1 As NXOpen.CAM.Preferences = Nothing Dim nXObject1 As NXOpen.NXObject = Nothing preferences1 = theSession.CAMSession.CreateCamPreferences() preferences1.ConfigurationFile = slctdcfgPathFile preferences1.TemplateFile = tmpltoptPathFile nXObject1 = preferences1.Commit() preferences1.Destroy() theUI.NXMessageBox.Show("Configuração Selecionada: ", NXOpen.NXMessageBox.DialogType.Information, String.Concat(slctdcfgFile, vbCrLf, tmpltoptFile)) End If End Sub Function ChooseOneString(ByRef prompt As String, ByRef choices As ArrayList) As String If choices.Count() = 1 Then Return choices(0).ToString Dim opts(13) As String Dim a As Integer = 0 Dim ii, resp, z As Integer Dim n_choices As Integer = choices.Count Do If (n_choices - a) < 14 Then z = n_choices - a Else z = 14 End If For ii = 0 To z - 1 opts(ii) = choices(a + ii) Next If ((z = 14) And ((a + z) < n_choices)) Then opts(13) = "More..." theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) resp = theUFSession.Ui.DisplayMenu(prompt, 0, opts, z) theUFSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Select Case resp Case 1 ' Back If (a = 0) Then Return Nothing a = a - 13 Case 2 ' Cancel Return Nothing Case 18 ' More ... If ((a + z) < n_choices) Then a = a + 13 Case Else ' Picked one Return choices(a + resp - 5).ToString End Select Loop While True Return Nothing ' can't really get here End Function Sub ParseFullpathFilename(ByVal fullpathFilename As String, ByRef fullpath As String, ByRef filename As String, ByRef extension As String) Dim i As Integer = Nothing Dim splitFullpathFilename() As String = Nothing Dim filenameAndExtension() As String = Nothing splitFullpathFilename = fullpathFilename.Split("\"c) filenameAndExtension = splitFullpathFilename(splitFullpathFilename.Length - 1).Split("."c) filename = filenameAndExtension(0) extension = filenameAndExtension(filenameAndExtension.Length - 1) fullpath = "" For i = 0 To (splitFullpathFilename.Length - 2) fullpath = fullpath & splitFullpathFilename(i) & "\" Next i End Sub End Module

KB Article ID# PL8792650

Contents

SummaryDetails

Associated Components

NX Open - All Languages