Error While Looping Over Collection

Hello all!

NX10 - Strange error which only happens on a handful of drawings out of 50+. When looping over a collection in the part object it gets mad about something being changed/committed while looping? I can't figure it out. Any help is greatly appreciated! Cheers.

Error = "NXopen.NXException: Collection does not support modification while iteration in progress..."

It seems that the length of the collection changes while you are iterating over it. But without some more details (code) it is hard to say whar causes this.
Maybe you can post the code that throws this error?

You should not add to or delete from the collection that you are currently iterating. Doing so will cause errors. It appears that your code has violated this rule.

Hi. I am not changing the collection at all during the running of this loop. I do commit some changes so I was wondering if that was taking some time before it iterated?

For Each myDimension As Annotations.Dimension In workPart.Dimensions
Try
objects1(0) = myDimension

editSettingsBuilder1 = workPart.SettingsManager.CreateAnnotationEditSettingsBuilder(objects1)

If Left(TypeName(myDimension).ToUpper(),3) = "PMI" Then
editSettingsBuilder1.AnnotationStyle.LetteringStyle.DimensionTextSize = fontSize/scaleNum/scaleDen
editSettingsBuilder1.AnnotationStyle.LetteringStyle.AppendedTextSize = fontSize/scaleNum/scaleDen
editSettingsBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextSize = fontSize/scaleNum/scaleDen
Else
editSettingsBuilder1.AnnotationStyle.LetteringStyle.DimensionTextSize = fontSize
editSettingsBuilder1.AnnotationStyle.LetteringStyle.AppendedTextSize = fontSize
editSettingsBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextSize = fontSize
End If

editSettingsBuilder1.AnnotationStyle.LetteringStyle.DimensionTextLineWidth = currentFontLineWidth
editSettingsBuilder1.AnnotationStyle.LetteringStyle.AppendedTextLineWidth = currentFontLineWidth
editSettingsBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextLineWidth = currentFontLineWidth
editSettingsBuilder1.AnnotationStyle.LetteringStyle.DimensionTextFont = fontNumber
editSettingsBuilder1.AnnotationStyle.LetteringStyle.AppendedTextFont = fontNumber
editSettingsBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextFont = fontNumber
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowheadWidth = currentLineWidth
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.FirstExtensionLineWidth = currentLineWidth
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.SecondExtensionLineWidth = currentLineWidth
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowheadWidth = currentLineWidth
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowLineWidth = currentLineWidth
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowLineWidth = currentLineWidth
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.SecondPosToExtensionLineDistance = 2.5
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.FirstPosToExtensionLineDistance = 2.5
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.LinePastArrowDistance2 = 1
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.LinePastArrowDistance = 1
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowType = NXOpen.Annotations.ArrowheadType.FilledArrow
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowType = NXOpen.Annotations.ArrowheadType.FilledArrow

nXObject1 = editSettingsBuilder1.Commit()
numGood = numGood + 1

Catch
numCatches = numCatches + 1
End Try
Next

Don't forget to destroy the builder object after the commit. Not doing so can lead to errors and/or strange behavior.