Reorder Standard Parameter in NX
Reorder Standard Parameter in NX
(OP)
Hi,
is there any way to reorder all standard parameters (p*) in NX (10/11)? I have a part which have currently up to parameter-number of 9000! This is a result of some pattern-features and some changes to them for different versions. So I have e.g. no parameters within 1000 to 2000 and more like that. So I want to renumber all parameters beginning with a "p".
Do any one of you have a tool, e.g. VB for that? Or do we have a standard function?
Best regards
Michael
is there any way to reorder all standard parameters (p*) in NX (10/11)? I have a part which have currently up to parameter-number of 9000! This is a result of some pattern-features and some changes to them for different versions. So I have e.g. no parameters within 1000 to 2000 and more like that. So I want to renumber all parameters beginning with a "p".
Do any one of you have a tool, e.g. VB for that? Or do we have a standard function?
Best regards
Michael





RE: Reorder Standard Parameter in NX
The program is provided as is and I take no responsibility for any issues that could be encountered :)
CODE --> .net
Imports NXOpen Imports System Imports System.Collections.Generic '' Renumber the all system expressions in workpart that match the specified regular expression Module rename_system_expressions Dim TS As Session Dim LW As ListingWindow Dim WP As Part Sub Main(ByVal args() As String) TS = Session.GetSession() WP = TS.Parts.Work LW = TS.ListingWindow Dim systemRegularExpression = "p[0-9]+" Dim pRegExp As Text.RegularExpressions.Regex = New Text.RegularExpressions.Regex(systemRegularExpression) Dim temporaryRegularExpression As String = "_temp_[0-9]+" Dim tmpRegExp As Text.RegularExpressions.Regex = New Text.RegularExpressions.Regex(temporaryRegularExpression) Dim undoMark As Session.UndoMarkId = TS.SetUndoMark(Session.MarkVisibility.Visible, "Renumber System Expressions") LW.Open() LW.WriteLine("Processing Expressions") Dim expDictionary As New SortedDictionary(Of String, Expression) Dim expArray As Expression() = WP.Expressions.ToArray '' find and give all matching expressions a temporary name For ii As Integer = 0 To expArray.Length - 1 Dim exp As Expression = expArray(ii) If pRegExp.IsMatch(exp.Name) Then Dim matchExp As String = pRegExp.Match(exp.Name).ToString() Dim pNumber As Integer = Text.RegularExpressions.Regex.Match(matchExp, "\d+").ToString() Dim uniqueKey As String = pNumber.ToString.PadLeft(100, "0") + "-" + ii.ToString Try WP.Expressions.SystemRename(exp, exp.Name + "_temp_" + ii.ToString) expDictionary.Add(uniqueKey, exp) Catch ex As Exception LW.WriteLine("Failed to rename " + exp.Name + " due to " + ex.Message) End Try End If Next '' Renumber the found expressions Dim newNameCounter As Integer = 0 For Each pair As KeyValuePair(Of String, Expression) In expDictionary Dim newName As String = "p" + newNameCounter.ToString Dim oldName As String = tmpRegExp.Replace(pair.Value.Name, "") Try WP.Expressions.SystemRename(pair.Value, newName) LW.WriteLine("Renamed " + oldName + " to " + newName) newNameCounter += 1 Catch ex As Exception LW.WriteLine("Failed to rename " + oldName + " with " + newName + " due to :" + ex.Message) End Try Next TS.UpdateManager.DoUpdate(undoMark) End Sub End ModuleRE: Reorder Standard Parameter in NX
Thank you! That works fine! Is it possible to modify it in that way, that if there are some parameters like "pattern_p*", that these parameters will get also the prefix "pattern_" after renaming?
Best regards
Michael
RE: Reorder Standard Parameter in NX
CODE --> VB.net
Imports NXOpen Imports System Imports System.Collections.Generic '' Renumber all system expressions in workpart that match the specified regular expression Module rename_system_expressions Dim TS As Session Dim LW As ListingWindow Dim WP As Part Sub Main(ByVal args() As String) TS = Session.GetSession() WP = TS.Parts.Work LW = TS.ListingWindow Dim systemRegularExpression = "p[0-9]+" Dim pRegExp As Text.RegularExpressions.Regex = New Text.RegularExpressions.Regex(systemRegularExpression) Dim temporaryRegularExpression As String = "_temp_[0-9]+" Dim tmpRegExp As Text.RegularExpressions.Regex = New Text.RegularExpressions.Regex(temporaryRegularExpression) Dim keepTextRegularExpression As String = "pattern_" Dim keepRegExp As Text.RegularExpressions.Regex = New Text.RegularExpressions.Regex(keepTextRegularExpression) Dim undoMark As Session.UndoMarkId = TS.SetUndoMark(Session.MarkVisibility.Visible, "Renumber System Expressions") LW.Open() LW.WriteLine("Processing Expressions") Dim expDictionary As New SortedDictionary(Of String, Expression) Dim expArray As Expression() = WP.Expressions.ToArray '' find and give all matching expressions a temporary name For ii As Integer = 0 To expArray.Length - 1 Dim exp As Expression = expArray(ii) If pRegExp.IsMatch(exp.Name) Then Dim matchExp As String = pRegExp.Match(exp.Name).ToString() Dim pNumber As Integer = Text.RegularExpressions.Regex.Match(matchExp, "\d+").ToString() Dim uniqueKey As String = pNumber.ToString.PadLeft(100, "0") + "-" + ii.ToString Try WP.Expressions.SystemRename(exp, exp.Name + "_temp_" + ii.ToString) expDictionary.Add(uniqueKey, exp) Catch ex As Exception LW.WriteLine("Failed to rename " + exp.Name + " due to " + ex.Message) End Try End If Next '' Renumber the found expressions Dim newNameCounter As Integer = 0 For Each pair As KeyValuePair(Of String, Expression) In expDictionary Dim newName As String = "p" + newNameCounter.ToString Dim oldName As String = tmpRegExp.Replace(pair.Value.Name, "") If keepRegExp.IsMatch(oldName) then newName = keepTextRegularExpression + newName End If Try WP.Expressions.SystemRename(pair.Value, newName) LW.WriteLine("Renamed " + oldName + " to " + newName) newNameCounter += 1 Catch ex As Exception LW.WriteLine("Failed to rename " + oldName + " with " + newName + " due to :" + ex.Message) End Try Next TS.UpdateManager.DoUpdate(undoMark) End Sub End Module