nx 8.5
first, thanks to NXjournaling.com. I spent whole day reading codes......seriously..
here is my code:
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
'get number of expressions in the part
'Dim NXexp() As Expression
'NXexp = workPart.Expressions.ToArray
'Dim noOfNXExp As Integer = NXexp.Length
Dim xlsData() As String
Using xlsFile As New Microsoft.VisualBasic.FileIO.TextFieldParser("E:\book.csv")
xlsFile.SetDelimiters(",")
xlsFile.TextFieldType = FileIO.FieldType.Delimited
xlsFile.HasFieldsEnclosedInQuotes = True
While Not xlsFile.EndOfData
xlsData = xlsFile.ReadFields()
For Each NXexp As Expression In workPart.Expressions
If NXexp.Name = xlsData(0) Then
NXexp.RightHandSide = xlsData(1)
Exit For
End If
Next
End While
End Using
End Sub
End Module
the excel book.csv looks like this:
a, 1
diameter, "if a<1 then 10else 15"
the main thing i did is to use TextFieldParser which can detect comma and quotation mark
interresting thing is after this line of code
xlsData = xlsFile.ReadFields()
i tried to use lw.writeline(xlsData) to see what happen, BUT the result is:
System. String[]
which i dont understand
i suspect that did VS divide xlsdata into two strings because the original lne is seperated by a comma
then i try
lw.writeline(xlsData (0))
it return a.
then, i keeping trying
lw.writeline(xlsData (1))
it returns 1
As you see, the code is EXTREMELY INEFFICIENT as it has to go through all expressions in NX, but it works....
question:
1) any better way to improve the code? I saw IsMatch sort of NX built in function but really dont know how to use it
2) to succeed, i use
For Each NXexp As Expression In workPart.Expressions
because initially i use
for i as integer = 0 to 999
If NXexp.
after i type If NXexp.
the VS inteliSense doesnt show up the name....
i still dont know how the expressions work exactly internally
first, thanks to NXjournaling.com. I spent whole day reading codes......seriously..
here is my code:
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
'get number of expressions in the part
'Dim NXexp() As Expression
'NXexp = workPart.Expressions.ToArray
'Dim noOfNXExp As Integer = NXexp.Length
Dim xlsData() As String
Using xlsFile As New Microsoft.VisualBasic.FileIO.TextFieldParser("E:\book.csv")
xlsFile.SetDelimiters(",")
xlsFile.TextFieldType = FileIO.FieldType.Delimited
xlsFile.HasFieldsEnclosedInQuotes = True
While Not xlsFile.EndOfData
xlsData = xlsFile.ReadFields()
For Each NXexp As Expression In workPart.Expressions
If NXexp.Name = xlsData(0) Then
NXexp.RightHandSide = xlsData(1)
Exit For
End If
Next
End While
End Using
End Sub
End Module
the excel book.csv looks like this:
a, 1
diameter, "if a<1 then 10else 15"
the main thing i did is to use TextFieldParser which can detect comma and quotation mark
interresting thing is after this line of code
xlsData = xlsFile.ReadFields()
i tried to use lw.writeline(xlsData) to see what happen, BUT the result is:
System. String[]
which i dont understand
i suspect that did VS divide xlsdata into two strings because the original lne is seperated by a comma
then i try
lw.writeline(xlsData (0))
it return a.
then, i keeping trying
lw.writeline(xlsData (1))
it returns 1
As you see, the code is EXTREMELY INEFFICIENT as it has to go through all expressions in NX, but it works....
question:
1) any better way to improve the code? I saw IsMatch sort of NX built in function but really dont know how to use it
2) to succeed, i use
For Each NXexp As Expression In workPart.Expressions
because initially i use
for i as integer = 0 to 999
If NXexp.
after i type If NXexp.
the VS inteliSense doesnt show up the name....
i still dont know how the expressions work exactly internally