×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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

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

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

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

(OP)
I am so excited!!!!!!

thank you very much!

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

one step forward toward drawing automation process

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources