Right now I am writing some code that automatically finds all the start and end points of line segments to be placed in an ordinate set.
I currently have code that creates a set on the left and right side, however, because 2 separate collections are required they sometimes have values that overlap. For example, both sides have a 1 1/2 measurement. I would like to only have one on the left side.
I have been trying to write a function to compare the 2 lists and remove any value that is the same in the second list, but I have had no success getting it to work. Part of the kicker is that the first entry in both lists will be the same and has to avoid deletion.
Any help would be appreciated.
Public Function CheckForDuplicates (Col1 As ObjectCollection, Col2 As ObjectCollection) As ObjectCollection Dim FirstPoint As GeometryIntent Dim SecondPoint As GeometryIntent Dim oNewCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection For item =1 To Col2.Count oNewCol.Add(Col2.Item(item)) Next For i=2 To Col1.Count FirstPoint = Col1.Item(i) For j=1 To Col2.Count SecondPoint = Col2.Item(j) If FirstPoint.PointOnSheet.X = SecondPoint.PointOnSheet.X Or FirstPoint.PointOnSheet.Y = SecondPoint.PointOnSheet.Y oNewCol.Remove(j) End If Next Next Return oNewCol End Function
Right now I am writing some code that automatically finds all the start and end points of line segments to be placed in an ordinate set.
I currently have code that creates a set on the left and right side, however, because 2 separate collections are required they sometimes have values that overlap. For example, both sides have a 1 1/2 measurement. I would like to only have one on the left side.
I have been trying to write a function to compare the 2 lists and remove any value that is the same in the second list, but I have had no success getting it to work. Part of the kicker is that the first entry in both lists will be the same and has to avoid deletion.
Any help would be appreciated.
Public Function CheckForDuplicates (Col1 As ObjectCollection, Col2 As ObjectCollection) As ObjectCollection Dim FirstPoint As GeometryIntent Dim SecondPoint As GeometryIntent Dim oNewCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection For item =1 To Col2.Count oNewCol.Add(Col2.Item(item)) Next For i=2 To Col1.Count FirstPoint = Col1.Item(i) For j=1 To Col2.Count SecondPoint = Col2.Item(j) If FirstPoint.PointOnSheet.X = SecondPoint.PointOnSheet.X Or FirstPoint.PointOnSheet.Y = SecondPoint.PointOnSheet.Y oNewCol.Remove(j) End If Next Next Return oNewCol End Function
Hi @MTheDesigner. I created a Sub routine you can try out to see if it will would work better for you than the Function. The two input object collections are added ByRef so that it will effect the source objects, instead of creating a new third one, since all we really need is to eliminate duplicates within the second one.
Public Sub EliminateDuplicates(ByRef Col1 As ObjectCollection, ByRef Col2 As ObjectCollection)
Dim Col1First As GeometryIntent = Col1.Item(1)
Dim Col2First As GeometryIntent = Col2.Item(1)
For Each oObj1 In Col1
If oObj1 Is Col1First Then Continue For
Dim Col1GInt As GeometryIntent = oObj1
For Each oObj2 In Col2
If oObj2 Is Col2First Then Continue For
Dim Col2GInt As GeometryIntent = oObj2
If Col1GInt.PointOnSheet.X = Col2GInt.PointOnSheet.X Or _
Col1GInt.PointOnSheet.Y = Col2GInt.PointOnSheet.Y Then
Col2.RemoveByObject(oObj2)
End If
Next
Next
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
Hi @MTheDesigner. I created a Sub routine you can try out to see if it will would work better for you than the Function. The two input object collections are added ByRef so that it will effect the source objects, instead of creating a new third one, since all we really need is to eliminate duplicates within the second one.
Public Sub EliminateDuplicates(ByRef Col1 As ObjectCollection, ByRef Col2 As ObjectCollection)
Dim Col1First As GeometryIntent = Col1.Item(1)
Dim Col2First As GeometryIntent = Col2.Item(1)
For Each oObj1 In Col1
If oObj1 Is Col1First Then Continue For
Dim Col1GInt As GeometryIntent = oObj1
For Each oObj2 In Col2
If oObj2 Is Col2First Then Continue For
Dim Col2GInt As GeometryIntent = oObj2
If Col1GInt.PointOnSheet.X = Col2GInt.PointOnSheet.X Or _
Col1GInt.PointOnSheet.Y = Col2GInt.PointOnSheet.Y Then
Col2.RemoveByObject(oObj2)
End If
Next
Next
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.