Edge or Face by point coordinates

by Vladimir Ananyev

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

   

<

p style=”line-height: normal;margin: 0cm 0cm 0pt” class=”MsoNoSpacing”>End Sub


Comments

2 responses to “Edge or Face by point coordinates”

  1. Is there any way to select the edge which lie within two points (startVertex and stopVertix). I am not able to select specific edge on the body when there is many edges connected to certain point like corner point.

  2. If you have several edges that share the same start and end vertices then you should provide some extra information to select only one of them.
    Could you please post this question on the Inventor Customization forum:
    http://forums.autodesk.com/t5/inventor-customization/bd-p/120
    Please provide also the part model you use for tests.
    Thanks

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading