Inspired by the example process being used in that article linked to above, where only the one object type is being dealt with (SketchPoint), but wanting to find a different, and possibly better, or more efficient way to do it than using the PartComponentDefinition.FindUsingPoint method for finding other SketchPoint objects, I decided to give this a try myself, because it is interesting and potentially useful to me. In this example, I also expect a PlanarSketch to be 'active', to keep it relatively simple, however I also include some error proofing and feedback for when that is not the case. Then, since we already have a SketchPoints collection specifically for this active sketch, I simply decided to iterate that collection a second time for each SketchPoint, to keep it simple. Due to the method being used (Merge) in this loop, and the nature of how these types of iterations work, it sometimes encounters a SketchPoint where accessing its SketchPoint.Geometry property will throw an error, so I incorporated a couple Try...Catch...End Try statements in there to avoid those occasions, for error proofing. All my tests with this code on unconstrained sketches so far have been successful, so it seems to work just fine.
The efficiency of this process could likely be improved further if we could use a secondary collection for the inner iteration that got the outer iteration's SketchPoint removed from it each time, but I'm not sure if that is possible, since the collection of an iteration only gets evaluated once (before the iteration starts). I have not done comparison processing time studies on multiple ways of doing this process, to see which one is faster, but I suspect that unless your sketch has thousands of SketchPoints in it, there likely won't be much noticeable difference.
Just throwing this one out there too. They say variety is the spice of life after all.
Dim oActiveObj = ThisApplication.ActiveEditObject
If oActiveObj Is Nothing OrElse (Not TypeOf oActiveObj Is PlanarSketch) Then
MsgBox("You must be in 'Edit Mode' of a PlanarSketch for this rule to work!", vbCritical, "iLogic")
Return
End If
Dim oPSketch As PlanarSketch = oActiveObj
For Each oSPoint As SketchPoint In oPSketch.SketchPoints
Dim oP2d As Point2d = Nothing
Try : oP2d = oSPoint.Geometry : Catch : Continue For : End Try
If oP2d Is Nothing Then Continue For
For Each oOtherSPoint As SketchPoint In oPSketch.SketchPoints
If oOtherSPoint Is oSPoint Then Continue For
Dim oP2d2 As Point2d = Nothing
Try : oP2d2 = oOtherSPoint.Geometry : Catch : Continue For : End Try
If oP2d2 Is Nothing Then Continue For
If oP2d2.IsEqualTo(oP2d, 0.001) Then
oOtherSPoint.Merge(oSPoint)
End If
Next oOtherSPoint
Next oSPoint
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

(Not an Autodesk Employee)