Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

try to write code to loop through tolerance on drawing,but got some trouble

Status
Not open for further replies.

godpaul

Automotive
Joined
May 4, 2014
Messages
119
Location
US
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 .GetAppendedText method will return an AppendedText object; the .ToString method of the AppendedText object outputs a string representation of the object, not the appended text itself. In relation to the dimension, appended text can be placed above, below, before, after, or any combination thereof. Now that you have the AppendedText object, you can use the .GetAboveText, .GetAfterText, .GetBeforeText, and .GetBelowText methods; each of which returns an array of strings, each index in the array represents a line of the text.

For the tolerance type error, try importing NXOpen.Annotations
OR
change the references to the tolerance type enumeration from (for example)
= ToleranceType.None
to
= Annotations.ToleranceType.None

www.nxjournaling.com
 
I am so excited!!!!!!

thank you very much!

looping through tolerance succeeded!!!!!!!!

one step forward toward drawing automation process
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top