Hey,
I am trying to write a simple script to remove duplicated polylines.
the polylines are closed edges of trangular surfaces. each surface has more than 2 duplicates. what i am trying to do is to find the contre of each polyline. if the centres are the same, polyline will be removed from the list.
Here is my script:
Dim i As Integer
Dim j As Integer
Dim threshold As Integer:threshold = 1
Dim cen As New Point3d
Dim pLine As New Polyline
Dim pList As New list(Of Polyline):pList = x
Dim cenT As New Point3d
Dim pLineT As New polyline
For i = 0 To x.Count - 1
pLine = x(i)
cen = pLine.CenterPoint
For j = 0 To x.Count - 1
If Not j = i Then
pLineT = x(j)
cenT = pLineT.CenterPoint
If cen.DistanceTo(cenT) <= threshold Then
pList.removeat(j)
End If
End If
Next
Next
A = indexList
I think I have found the problem which is: duplicated polylines are being removed more than one time. but I can't find the right syntax to correct it....
Help!!!!
many thanks in advance!!
Kwo
the status Kuo
hey guys,
i think i have solved the problem by myself. In stead of removing objects from a list, now i just create a new empty list to add non-repeated objects in.
cheers
Jul 6, 2012
David Rutten
Hi Kwo,
if you're removing items from a collection, you should iterate over it backwards. If you iterate forwards you have to adjust your iteration variable on every remove. There were other weird things in your code, a lot of pointless New keywords. Below is how I would write it.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Jul 6, 2012