looping over particular body surface to get it's ID

Options
Happy Kumar
Happy Kumar Member Posts: 6
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: 279
    First Anniversary First Comment 5 Likes Ansys Employee
    Options

    I assume this is ANSYS Mechanical…

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

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

    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, Employee Posts: 124
    First Answer Name Dropper First Anniversary Ansys Employee
    edited April 29
    Options

    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: 6
    First Comment
    edited April 30
    Options

    Thanks Erik :)

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

    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)