How can we in an automatic way do the same as function: Go To -> Joints For Selected Bodies

Erik Kostson
Erik Kostson Member, Moderator, Employee Posts: 280
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited 10:23AM in Structures

How can we in an automatic way, e.g., via mechanical scripting, do the same as function: Go To -> Joints For Selected Bodies?

Best Answer

  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 280
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited 10:22AM Answer ✓

    Below is one way of doing this (it has 2 steps - 1st select body, and find all faces belonging to it, and 2nd see if these faces are scoped in any connections/joints):

    model=ExtAPI.DataModel.Project.Model # refer to Model
    analysis = model.Analyses[0]
    solution = analysis.Solution
    myfaces=[]
    myjnts=[]
    
    #get faces of selected bodies
    cursel=ExtAPI.SelectionManager.CurrentSelection.Ids
    for cid in cursel:
        my_geobody =ExtAPI.DataModel.GeoData.GeoEntityById(cid)
        if (my_geobody.GetType())==(Ansys.ACT.Common.Geometry.GeoBodyWrapper):
            for face in my_geobody.Faces:
                myfaces.append(face.Id)
        else:
            print('Not a body - select a body')
    
    #check if faces are part of joints
    def findcon(myfaces):
        connections = model.Connections
        jns=connections.GetChildren(DataModelObjectCategory.Joint,True)
        for jnt in jns:
            mid=jnt.MobileLocation.Ids[0]
            rid=jnt.ReferenceLocation.Ids[0]
            for f in myfaces:
                if f==rid or f ==mid:
                    print('Got one: ' + jnt.Name)
                    myjnts.append(jnt)
        ExtAPI.DataModel.Tree.Activate(myjnts)
    
    findcon(myfaces)
    

    The above can also be used to get the function go to -> Contacts for Selected Bodies

    We need then to change the DataModelObjectCategory.Joint to DataModelObjectCategory.ContactRegion, and the subsequent Mob./Ref. Location to the contact source and target locations.

This discussion has been closed.