changing the location of external spread sheet in unigraphics NX 7.5
changing the location of external spread sheet in unigraphics NX 7.5
(OP)
hi, i have a large assembly with many parts and sub assemblies, the dimensions in the part and assemblies are derived from expressions , many of which are linked to a external spreadsheet ,the problem is if the entire folder is transferred to another computer ,the default location of the spreadsheet in the expression remains the same,that is c:\users\"username"\desktop\"folder name"\"sub-folder name"\"spreadsheet name".xlsx .Is there a option in unigraphics NX7.5 to change the location of the external spreadsheet from which ug reads the value from .....it would be impossible to edit the location of the spreadsheet in expressions manually .





RE: changing the location of external spread sheet in unigraphics NX 7.5
Now if this is something that is going to be a common issue with you, then perhaps a little preplanning would be worth your time and effort.
The easiest of these approaches would be to create a String Expression equal to the path to the folder where the spreadsheet is located and then use this variable in all of your expressions which referencs the spreadsheet, as shown below:
Now all you have to do is edit a single expression, 'sheet', to change the paths to all of the other expressions.
Now if you want to get really elegant, and you're doing this all of the time and you's like the files to always be correct no matter where you moved the part files to, try this scenario:
Create a folder somewhere where you will place ALL of the spreadsheets which will be referenced by any of your part models and let's say the path to this folder is 'D:\User_files\Spreadsheets'. Now create a unique Environment Variable in your system or user profile similar to (be sure to include that last '\'):
NX_SPREADSHEETS=D:\User_files\Spreadsheets\
Now whenever you create a Part file where you're going to be using one of the spreadsheets in this common folder, just create an expressions which references this Environment Variable (you could pre-define this expression in you modeling templated is you wish) which will now look like:
Now no matter where the part files are located as long as the spreadsheets remain in that same common location, you should be good to go.
John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:
To an Engineer, the glass is twice as big as it needs to be.
RE: changing the location of external spread sheet in unigraphics NX 7.5
I think the process is more tedious than impossible. Sounds like a good time to use a journal.
The code below will gather up the file names of the spreadsheets referenced in your file and prompt for replacement files (cell/range references within the file are left as-is). The code could even be modified to implement John's excellent suggestion. I'll leave that as an exercise for the reader.
CODE
' June 11, 2012
' NX 7.5.0.32
' find expressions that reference an external excel file, prompt for replacement file
Option Strict Off
Imports System
Imports NXOpen
Imports System.Text.RegularExpressions
Imports System.Collections.Generic
Imports System.IO
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim i As Integer = 0
Dim re As New Regex("(ug_excel_read|ug_cell_read|ug_cell_hlookup|ug_cell_vlookup)\s?\(\s?\""(.+\.xls(x|m)?)")
Dim excelFile As String
Dim newExcelFile As String
Dim originalExcelFiles As New List(Of String)
Dim myExcelFiles As New Dictionary(Of String, String)
Dim myExpressions As Expression()
Dim myExcelExpressions As New Dictionary(Of Expression, String)
myExpressions = workPart.Expressions.ToArray()
lw.Open()
For Each myExp As Expression In myExpressions
If re.IsMatch(myExp.RightHandSide) Then
excelFile = re.Match(myExp.RightHandSide, 0).Groups(2).ToString
myExcelExpressions.Add(myExp, excelFile)
If Not originalExcelFiles.Contains(excelFile) Then
originalExcelFiles.Add(excelFile)
End If
i += 1
End If
Next
For Each Str As String In originalExcelFiles
newExcelFile = ReplacementFile(Str)
If newExcelFile <> "" Then
myExcelFiles.Add(Str, newExcelFile)
Else
MsgBox("Cancel pressed, journal exiting.", MsgBoxStyle.OkOnly, "Journal canceled")
End If
Next
Dim pair As KeyValuePair(Of Expression, String)
For Each pair In myExcelExpressions
lw.WriteLine("Old: " & pair.Key.Name & " = " & pair.Key.RightHandSide)
lw.WriteLine("New: " & pair.Key.Name & " = " & Replace(pair.Key.RightHandSide, pair.Value, myExcelFiles(pair.Value)))
lw.WriteLine("")
pair.Key.RightHandSide = Replace(pair.Key.RightHandSide, pair.Value, myExcelFiles(pair.Value))
Next
If i = 0 Then
lw.WriteLine("No expression names matched the specified regular expression")
End If
lw.WriteLine("Expression processing finished.")
lw.Close()
End Sub
Function ReplacementFile(ByVal oldFile As String) As String
Dim fdlg As OpenFileDialog = New OpenFileDialog()
fdlg.Title = "Select replacement for: " & oldFile
fdlg.InitialDirectory = "C:\"
fdlg.Filter = "Excel Files(*.XLS;*.XLSX;*.XLSM)|*.XLS;*.XLSX;*.XLSM"
fdlg.FilterIndex = 2
fdlg.RestoreDirectory = True
If fdlg.ShowDialog() = DialogResult.OK Then
Return fdlg.FileName
Else
Return ""
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module
www.nxjournaling.com
RE: changing the location of external spread sheet in unigraphics NX 7.5
The section of code:
CODE
MsgBox("Cancel pressed, journal exiting.", MsgBoxStyle.OkOnly, "Journal canceled")
End If
Should read:
CODE
MsgBox("Cancel pressed, journal exiting.", MsgBoxStyle.OkOnly, "Journal canceled")
Exit Sub
End If
If you don't add that line, the journal will keep going after you press cancel (if you should choose to do so) and may run into problems as a result.
www.nxjournaling.com
RE: changing the location of external spread sheet in unigraphics NX 7.5