In Mechanical is there a way to rename a group of bodies based on their vertical position? For example, rename a column of solid bolt geometries so that their Name varies sequentially based on their position in the column e.g. A1, A2, A3.
You can get the body centroids and then sort them by the value of your choice. For example the Centroid[1] index is the Y axis globally. Example below assumes you have a Named Selection (NS) to start with as the group. If you don't you can get this object by a name or id.
Bodies = NS.Entities SortedBodies= sorted(Bodies , key=lambda B: B.Centroid[1]) #assumes Y is vertical position. for Index, B in enumerate(SortedBodies): TreeBody = ExtAPI.DataModel.Project.Model.Geometry.GetBody(B) TreeBody.Name="A"+str(Index+1)