Enumerator Container Modifications

Enumerator Container Modifications

dustinbagley
Advocate Advocate
385 Views
1 Reply
Message 1 of 2

Enumerator Container Modifications

dustinbagley
Advocate
Advocate

I want to modify the following rule (which pulls the drawing curves from a document) so that the enumerator only contains kLineSegmentCurves instead of all curve types by either only adding kLineSegmentCurves or removing everything but after the fact. It currently contains a loop that successfully finds the curves by type. But I'm not sure how to remove them from the collection.

 

Dim oCurves As DrawingCurvesEnumerator
Dim oCurve As DrawingCurve 

oCurves = oView.DrawingCurves(oModel)
	For Each oCurve In oView.DrawingCurves(oModel)
		If oCurve.CurveType.ToString = "kLineSegmentCurve"
		Else
			'Remove oCurve from oCurves
		End If
	Next
curveMax = oCurves.Count
If curveIndex > curveMax Then
	curveIndex = curveMax
End If
oCurve = oView.DrawingCurves(oModel).Item(curveIndex)

 

0 Likes
Accepted solutions (1)
386 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor
Accepted solution

Hi @dustinbagley.  My main suggestion would be to convert the 'DrawingCurvesEnumerator' object into something else, like a List (or similar), that is easier to use, then use the filter to remove the items from it as needed.  A basic way to do this would be to create a variable for the other type of collection first, then use a For Each loop to copy the enumerator's contents into it.  My example below shows another possible way too.  The main thing going wrong in your code above is that you are collecting the curves in 3 different places.  You need to get the curves collection one time to a variable first, then use that variable from there on, instead of collecting the curves again and again.

 

When trying to help you with your code, I had no idea how you defined your 'oView' or 'oModel' variables, so I had to define all of the needed object variables ahead of that point, and set values to them before my code would make any sense.  So, the first 4 lines are part of that example built-up.  You may be using something completely different to get up to that point, and I have no idea what type of object your 'oModel' variable holds.  Also, if that oModel object is not seen in that specific view, it may not return any drawing curves and/or may throw an error.  I am not sure what you plan on doing with these DrawingCurves once you have them, so I did not know what type of collection type variable may be best for your situation either.

 

Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oView As DrawingView = oDDoc.ActiveSheet.DrawingViews.Item(1)
Dim oViewDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oComp As ComponentOccurrence = oViewDoc.ComponentDefinition.Occurrences.Item(1)
Dim oDCurves As DrawingCurvesEnumerator = Nothing
Try
	oDCurves = oView.DrawingCurves(oComp)
Catch
	Logger.Error("Error getting DrawingCurves of input model geometry.")
	Exit Sub
End Try
If IsNothing(oDCurves) OrElse oDCurves.Count = 0 Then Exit Sub
Dim oDCurvesList As List(Of DrawingCurve) = oDCurves.Cast(Of DrawingCurve).ToList
For Each oDCurve As DrawingCurve In oDCurvesList
	If oDCurve.CurveType <> CurveTypeEnum.kLineSegmentCurve Then
		oDCurvesList.Remove(oDCurve)
	End If
Next

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)