Determining duplicate entities in a sketch

Determining duplicate entities in a sketch

Anonymous
Not applicable
558 Views
4 Replies
Message 1 of 5

Determining duplicate entities in a sketch

Anonymous
Not applicable
Given a selection set in a sketch, how can I determine which entities lie on top of one another (duplicates)? Similar to the AutoCAD Overkill command - we have some sketches to clean up.

Thanks for any help.
0 Likes
559 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
There's nothing built into the API to help with this. You'll need to do a
geometric comparison to see if they're the same. For example, first check
to see if they're the same type, they're both lines or both circles, etc.
Then check to see if they're geometrically the same (same end points for
lines, same center and radius for circles, etc.). Another issue is that
once you've found a duplicate is deciding which one to delete. They may
have constraints on them so deleting either one of them could cause other
problems within the sketch. Ideally, you would recreate the constraints
that are on the entity to be deleted.
--
Brian Ekins
Autodesk Inventor API


wrote in message news:5243597@discussion.autodesk.com...
Given a selection set in a sketch, how can I determine which entities lie on
top of one another (duplicates)? Similar to the AutoCAD Overkill command -
we have some sketches to clean up.

Thanks for any help.
0 Likes
Message 3 of 5

Anonymous
Not applicable
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?
0 Likes
Message 4 of 5

Anonymous
Not applicable
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?
0 Likes
Message 5 of 5

Anonymous
Not applicable
Wow! Thanks Brian, that was much more than I expected thanks again for your time!

Todd
0 Likes