Sim77Son
Mechanical
- Aug 4, 2012
- 18
Hello,
first to explain what I try to do:
First I read out the filename from a NX part (NX version 10) which looks in our company like this (1521w1_0.115, 1521w1_St_01, 1521w1_z_BG and so on).
Then I look with InStr for the "_" and add 1 to the result so I get a number for the Mid function. The result till now is our position number (1521w1_0.115==>0.115, 1521w1_St_01==>St_01, 1521w1_z_BG==>z_BG).
But now my problem, I need to replace all results which are like this St_01, St_02, St_03 with a special number. That means St_01 will be replaced with 01.100, St_02 will be replaced with 02.100 and so on.
At the end I will write an attribute called POS which contains either the result from POS or if the partname was St_01 the result of POS2.
Here what I have done till now:
Imports NXOpen
Imports System.Text.RegularExpressions
Module NXJournal
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim Ergebnis As String
Dim zeichenposition As String
' das ist der filename ohne endung
Dim filename As String = workPart.Leaf
System.Windows.Forms.MessageBox.Show(filename)
' anzahl der zeichen
Ergebnis = InStr(1, filename, "_")
System.Windows.Forms.MessageBox.Show(Ergebnis)
zeichenposition = (Ergebnis + 1).ToString()
System.Windows.Forms.MessageBox.Show(zeichenposition)
' gibt aus "Positionsnummer"
Dim POS As String = Mid(filename, zeichenposition)
System.Windows.Forms.MessageBox.Show(POS)
' Stationen abändern
Dim POS2 As String
POS2 = POS.replace("St_01", "01.100")
POS2 = POS.replace("St_02", "02.100")
System.Windows.Forms.MessageBox.Show(POS2)
' Attribute
workPart.SetAttribute("POS", POS)
End Sub
End Module
first to explain what I try to do:
First I read out the filename from a NX part (NX version 10) which looks in our company like this (1521w1_0.115, 1521w1_St_01, 1521w1_z_BG and so on).
Then I look with InStr for the "_" and add 1 to the result so I get a number for the Mid function. The result till now is our position number (1521w1_0.115==>0.115, 1521w1_St_01==>St_01, 1521w1_z_BG==>z_BG).
But now my problem, I need to replace all results which are like this St_01, St_02, St_03 with a special number. That means St_01 will be replaced with 01.100, St_02 will be replaced with 02.100 and so on.
At the end I will write an attribute called POS which contains either the result from POS or if the partname was St_01 the result of POS2.
Here what I have done till now:
Imports NXOpen
Imports System.Text.RegularExpressions
Module NXJournal
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim Ergebnis As String
Dim zeichenposition As String
' das ist der filename ohne endung
Dim filename As String = workPart.Leaf
System.Windows.Forms.MessageBox.Show(filename)
' anzahl der zeichen
Ergebnis = InStr(1, filename, "_")
System.Windows.Forms.MessageBox.Show(Ergebnis)
zeichenposition = (Ergebnis + 1).ToString()
System.Windows.Forms.MessageBox.Show(zeichenposition)
' gibt aus "Positionsnummer"
Dim POS As String = Mid(filename, zeichenposition)
System.Windows.Forms.MessageBox.Show(POS)
' Stationen abändern
Dim POS2 As String
POS2 = POS.replace("St_01", "01.100")
POS2 = POS.replace("St_02", "02.100")
System.Windows.Forms.MessageBox.Show(POS2)
' Attribute
workPart.SetAttribute("POS", POS)
End Sub
End Module