Without writing the code and thinking through all the issues there's
probably something I'm not considering, but if I was going to write
something like this I would probably not do anything too fancy. The API
provides sketch entities by type so it's just a matter of comparing each
entity with the collection with every other entity. Below is the start of
this. This will compare all lines a sketch and report duplicates. One
thing to be careful of is when comparing values. Notice that I never
directly compare any values but instead check to see if they're the same
within a given tolerance. This is because of how floating point numbers are
handled by computers. There have been some previous discussions about this
issue.
Public Sub FindDuplicates()
Dim oSketch As Sketch
Set oSketch = ThisApplication.ActiveEditObject
' Check for duplicate lines.
Dim oLines As SketchLines
Set oLines = oSketch.SketchLines
Dim i As Integer
For i = 1 To oLines.Count
Dim j As Integer
For j = i + 1 To oLines.Count
Dim oSS As SelectSet
Set oSS = ThisApplication.ActiveDocument.SelectSet
oSS.Clear
oSS.Select oLines.Item(i)
oSS.Select oLines.Item(j)
If IdenticalLines(oLines.Item(i), oLines.Item(j)) Then
MsgBox "Found two identical lines"
End If
Next
Next
End Sub
' Compare two sketch lines to see if they're geometrically the same.
Private Function IdenticalLines(ByVal Line1 As SketchLine, ByVal Line2 As
SketchLine) As Boolean
' Initialize the return value.
IdenticalLines = False
' Do a trivial check of the length to eliminate most lines.
If WithinTol(Line1.Length, Line2.Length) Then
' Get the geometry definitions from the sketch entities.
Dim oLineSeg1 As LineSegment2d
Dim oLineSeg2 As LineSegment2d
Set oLineSeg1 = Line1.Geometry
Set oLineSeg2 = Line2.Geometry
' Check to see if the start point of line 1 matches either the start
or end point of line 2.
If WithinTol(oLineSeg1.StartPoint.DistanceTo(oLineSeg2.StartPoint),
0) Then
If WithinTol(oLineSeg1.EndPoint.DistanceTo(oLineSeg2.EndPoint),
0) Then
IdenticalLines = True
Exit Function
End If
ElseIf
WithinTol(oLineSeg1.StartPoint.DistanceTo(oLineSeg2.EndPoint), 0) Then
If
WithinTol(oLineSeg1.EndPoint.DistanceTo(oLineSeg2.StartPoint), 0) Then
IdenticalLines = True
Exit Function
End If
End If
End If
End Function
Private Function WithinTol(ByVal Value1 As Double, ByVal Value2 As Double)
As Boolean
If Abs(Value1 - Value2) <= 0.0000001 Then
WithinTol = True
Else
WithinTol = False
End If
End Function
--
Brian Ekins
Autodesk Inventor API
wrote in message news:5244085@discussion.autodesk.com...
That's pretty much what I thought. So I'm guessing I'll need to store all
the entities, endpoints, and direction of each entity and compare them -
what's best for this - arrays, recordsets, hash lists?