looping over particular body surface to get it's ID
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
-
I assume this is ANSYS Mechanical…
Ids = [F.Id for F in MyBody.Faces]
1 -
Thanks Mike, for your comment.
I have name selection of bodies and want loop over those bodies for their ids.0 -
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
Erik0 -
Thanks Erik
1 -
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)
0