looping over particular body surface to get it's ID

Happy Kumar
Happy Kumar Member Posts: 16
First Anniversary First Comment
**

How I can get reference Id of surface of a particular body. Please kindly help me with this and don't use current selection.

Comments

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 367
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    I assume this is ANSYS Mechanical…

    Ids = [F.Id for F in MyBody.Faces]

  • Happy Kumar
    Happy Kumar Member Posts: 16
    First Anniversary First Comment
    **

    Thanks Mike, for your comment.
    I have name selection of bodies and want loop over those bodies for their ids.

  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 282
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited April 2024

    Hi

    The below example might be what is needed. It assumes one wants 3D solid bodies and then to get their Faces and Ids - if surface bodies are also of interest, then just add to the if: an or condition to get also surface bodies :

    model = ExtAPI.DataModel.Project.Model
    analysis=model.Analyses[0]
    ns=model.NamedSelections.Children # named selections
    for n in ns: # loop through ns 
        nId=n.Location.Ids # only bodies in ns so nId is body id also
        for body in nId: # loop through and find 3D body
            b=ExtAPI.DataModel.GeoData.GeoEntityById(body)
            if str(b.BodyType)=="GeoBodySolid": # if Solid Body (no face/sheets) # or str(b.BodyType)=="GeoBodySheet": # if Solid Body and Surface bodies are used
                faces = b.Faces
                for face in faces:
                    fid=face.Id
                    print(fid)
    
    

    Thank you
    Erik

  • Happy Kumar
    Happy Kumar Member Posts: 16
    First Anniversary First Comment
    **
    edited April 2024

    Thanks Erik :)

  • Happy Kumar
    Happy Kumar Member Posts: 16
    First Anniversary First Comment
    **

    Hi Erik
    I am getting this error "iteration over non-sequence of type NamedSelection " because of below code I am not able to get the Id of particular nameselection containing bodies.Please Kindly help me with this.

    model = ExtAPI.DataModel.Project.Model
    ns=model.NamedSelections.Children[3] # named selections
    face1ID = []
    for n in ns: # loop through ns
    nId=n.Location.Ids # only bodies in ns so nId is body id also
    for body in nId: # loop through and find 3D body
    b=ExtAPI.DataModel.GeoData.GeoEntityById(body)
    if str(b.BodyType)=="GeoBodySolid": # if Solid Body (no face/sheets) # or str(b.BodyType)=="GeoBodySheet": # if Solid Body and Surface bodies are used
    faces = b.Faces
    for face in faces:
    fid=face.Id
    face1ID.append(fid)

    print("nameslection ID",face1ID)