Issue
How to find an Edge in the model given a point coordinate that lies on the Edge ?
Solution
This can be determined by using the 'LocateUsingPoint' method of the SurfaceBody object as shown in the following sample code: Point is defined by workpoint with hardcoded name.
C#
private void button1_Click(object sender, EventArgs e)
{
//get reference to active part document
PartDocument oDoc = (PartDocument)_InventorApp.ActiveDocument;
//get some workpoint in model by its name
WorkPoint wp = oDoc.ComponentDefinition.WorkPoints["wp4"];
try
{
//coordinate 3d-point
Inventor.Point pt = wp.Point;
// try to find edge
Object obj = oDoc.ComponentDefinition.SurfaceBodies[1]
.LocateUsingPoint(ObjectTypeEnum.kEdgeObject, pt, 0.1);
//// try to find face
//Object obj = oDoc.ComponentDefinition.SurfaceBodies[1]
// .LocateUsingPoint(ObjectTypeEnum.kFaceObject, pt, 0.1);
// visualize found object using document select set
oDoc.SelectSet.Select(obj);
}
catch
{
MessageBox.Show("Nothing selected at the specified point!",
"Find Edge or Face");
}
}
VB .NET
Private Sub Button1_Click(sender As System.Object, _
e As System.EventArgs) _
Handles Button1.Click
' get reference to active part document
Dim oDoc As PartDocument = TryCast(oApp.ActiveDocument, PartDocument)
' get some workpoint in model by its name
Dim wp As WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("wp1")
Try
' coordinate 3d-point
Dim pt As Inventor.Point = wp.Point
' try to find edge
Dim obj As Object = oDoc.ComponentDefinition.SurfaceBodies.Item(1) _
.LocateUsingPoint(ObjectTypeEnum.kEdgeObject, pt, 0.1)
'' try to find face
'Dim obj As Object = oDoc.ComponentDefinition.SurfaceBodies.Item(1) _
' .LocateUsingPoint(ObjectTypeEnum.kFaceObject, pt, 0.1)
' visualize found object using document select set
oDoc.SelectSet.Select(obj)
Catch ex As Exception
MessageBox.Show("Nothing selected at the specified point!",
"Find Edge or Face")
End Try
End Sub
VBA
Sub Find_EdgeByPoint()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim wp As WorkPoint
Set wp = oDoc.ComponentDefinition.WorkPoints.Item("wp4")
Dim pt As Point
Set pt = wp.Point
On Error Resume Next
Dim Obj As Object
Set Obj = oDoc.ComponentDefinition.SurfaceBodies.Item(1) _
.LocateUsingPoint(kEdgeObject, pt, 0.1)
' Set Obj = oDoc.ComponentDefinition.SurfaceBodies.Item(1) _
' .LocateUsingPoint(kFaceObject, pt, 0.1)
If Err.Number <> 0 Then
MsgBox "Nothing selected at the specified point!"
Else
oDoc.SelectSet.Select Obj
End If
End Sub