Discovery Import

Discovery Import

nearest item selection

    • Guillaume ANFOSSI
      Subscriber

      Hello,

      I am looking for a method to select by script an element close to another selection.

      For example, in the case below, I would like to retrieve from a face selection (1) the selection of the nearest edge (2)

       

      Is it possible ?

    • Devendra Badgujar
      Ansys Employee

      Hi GUICAD

      Let me check and get back to you on this.

    • Devendra Badgujar
      Ansys Employee

      Hi GUICAD

      Closest Edge to Secondary Selection...Text

      active=Selection.GetActive()
      if active.Count:
       item=active.Items[0]
       hitPoint = Window.ActiveWindow.ActiveContext.GetSelectionPoint(item)
       if isinstance(item,IDesignFace):
        closest=""
        dist=float('inf')
        for edge in item.Edges:
         project=edge.Shape.ProjectPoint(hitPoint)
         measuredDist=(project.Point.Vector-hitPoint.Vector).Magnitude
         if measuredDist(<)dist:
          dist=measuredDist
          closest=edge
      Selection.Create(closest).SetActiveSecondary()

      This should provide the key API needed, but you may need to change based on your needs. Let me know if this what you are looking for.

      Regards.

    • Guillaume ANFOSSI
      Subscriber

      Perfect, thanks !

Viewing 3 reply threads
  • You must be logged in to reply to this topic.