i try to loop through external CSV file so that the tolerance of each dimension on drawing can be updated.
the code is shown at the end;
the main idea is i give each dimension an appendedtext and it matches with the name in the CSV file, if matched, proceed to change tolerance
there are two big issues i encountered
the first one is at the beginning of the For each loop, i write
lw.WriteLine(dwgDimension.GetAppendedText.ToString)
in order to confirm NX can grab appendedtext. However, NX return all number, like 9898940694....
the second is after i run the code, NX gave me warning:
toleranceType is not declared. it may be inaccessible due to its protection level
what's my problem?
thank you
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
For Each sheet As Drawings.DrawingSheet In workPart.DrawingSheets
Dim partDimension() As Annotations.Dimension
partDimension = workPart.Dimensions.ToArray
Dim xlsData() As String
Using xlsFile As New Microsoft.VisualBasic.FileIO.TextFieldParser("E:\toleranceTest.csv")
xlsFile.SetDelimiters(",")
xlsFile.TextFieldType = FileIO.FieldType.Delimited
xlsFile.HasFieldsEnclosedInQuotes = True
While Not xlsFile.EndOfData
xlsData = xlsFile.ReadFields()
For Each dwgDimension As Annotations.Dimension In partDimension
lw.WriteLine(dwgDimension.GetAppendedText.ToString)
If dwgDimension.GetAppendedText.ToString = xlsData(0) Then
If (Double.Parse(xlsData(2)) And Double.Parse(xlsData(3)) = 0) Then
dwgDimension.ToleranceType = ToleranceType.None
ElseIf (Double.Parse(xlsData(2)) <> 0 Or Double.Parse(xlsData(3) <> 0)) Then
If (Double.Parse(xlsData(2)) + Double.Parse(xlsData(3)) = 0) Then
dwgDimension.ToleranceType = ToleranceType.BilateralOneLine
dwgDimension.UpperMetricToleranceValue = Double.Parse(xlsData(2))
dwgDimension.LowerMetricToleranceValue = Double.Parse(xlsData(2))
Else
dwgDimension.ToleranceType = ToleranceType.BilateralTwoLines
dwgDimension.UpperMetricToleranceValue = Double.Parse(xlsData(2))
dwgDimension.LowerMetricToleranceValue = Double.Parse(xlsData(3))
End If
End If
End If
Next
End While
End Using
Next
the code is shown at the end;
the main idea is i give each dimension an appendedtext and it matches with the name in the CSV file, if matched, proceed to change tolerance
there are two big issues i encountered
the first one is at the beginning of the For each loop, i write
lw.WriteLine(dwgDimension.GetAppendedText.ToString)
in order to confirm NX can grab appendedtext. However, NX return all number, like 9898940694....
the second is after i run the code, NX gave me warning:
toleranceType is not declared. it may be inaccessible due to its protection level
what's my problem?
thank you
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
For Each sheet As Drawings.DrawingSheet In workPart.DrawingSheets
Dim partDimension() As Annotations.Dimension
partDimension = workPart.Dimensions.ToArray
Dim xlsData() As String
Using xlsFile As New Microsoft.VisualBasic.FileIO.TextFieldParser("E:\toleranceTest.csv")
xlsFile.SetDelimiters(",")
xlsFile.TextFieldType = FileIO.FieldType.Delimited
xlsFile.HasFieldsEnclosedInQuotes = True
While Not xlsFile.EndOfData
xlsData = xlsFile.ReadFields()
For Each dwgDimension As Annotations.Dimension In partDimension
lw.WriteLine(dwgDimension.GetAppendedText.ToString)
If dwgDimension.GetAppendedText.ToString = xlsData(0) Then
If (Double.Parse(xlsData(2)) And Double.Parse(xlsData(3)) = 0) Then
dwgDimension.ToleranceType = ToleranceType.None
ElseIf (Double.Parse(xlsData(2)) <> 0 Or Double.Parse(xlsData(3) <> 0)) Then
If (Double.Parse(xlsData(2)) + Double.Parse(xlsData(3)) = 0) Then
dwgDimension.ToleranceType = ToleranceType.BilateralOneLine
dwgDimension.UpperMetricToleranceValue = Double.Parse(xlsData(2))
dwgDimension.LowerMetricToleranceValue = Double.Parse(xlsData(2))
Else
dwgDimension.ToleranceType = ToleranceType.BilateralTwoLines
dwgDimension.UpperMetricToleranceValue = Double.Parse(xlsData(2))
dwgDimension.LowerMetricToleranceValue = Double.Parse(xlsData(3))
End If
End If
End If
Next
End While
End Using
Next