How can we check the contact state and flip contact/target sides if needed?

Options
Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 823
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

With Mechanical scripting, how can we check the contact state and flip contact/target sides if needed?

Tagged:

Best Answer

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 823
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    The following function will check the contact state (well defined or unfulfilled) and flip contact/target sides if needed:

    def CheckContactState(body):
          ExtAPI.Log.WriteMessage("Checking contact status due to changing "+ str(body.Name) + "to rigid body")
          ExtAPI.DataModel.Tree.Refresh()
          contactRegions = ExtAPI.DataModel.Project.Model.GetChildren[Ansys.ACT.Automation.Mechanical.Connections.ContactRegion](True) 
          for contactRegion in contactRegions:
              if contactRegion.State==Ansys.ACT.Interfaces.Common.State.Unfulfilled :
                  contactRegion.FlipContactTarget()
          ExtAPI.DataModel.Tree.Refresh()  
    

Answers

  • Happy Kumar
    Happy Kumar Member Posts: 15
    First Comment
    Options

    Hi Pernelle, please explain how this scripts works as I am not able see any difference in contact and target.

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 823
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    Hi @Happy Kumar , this script will reverse contact/target only if the contact is unfulfilled (blue question mark next to the contact). If it is well defined (green tick mark) it will do nothing.

  • Happy Kumar
    Happy Kumar Member Posts: 15
    First Comment
    Options

    Thanks, Pernelle for your response :)