Get centroid of 2 semicircular end cap faces on cylinders?
Erik Kostson
Member, Employee Posts: 202
✭✭✭✭
Say we have 2 semi-circular faces as end caps on a cylinder (see image below). We would like to extract the centre point (see red dot at the centre of the face shown below) and not the centroid of the individual faces (see 2 red crosses on the 2 faces shown below. How can this be done by scripting?
0
Best Answer
-
Below is a sample code to be tailored and used as needed, showing one possible way of doing this:
def compare(a,b): global aedges global bedges aedges=a.Edges bedges=b.Edges if a.SurfaceType==GeoSurfaceTypeEnum.GeoSurfacePlane and b.SurfaceType==GeoSurfaceTypeEnum.GeoSurfacePlane: for ii in range(len(aedges)): for jj in range(len(bedges)): if aedges.Count==bedges.Count==2 and aedges[ii].Length==bedges[jj].Length and aedges[ii].Id==bedges[jj].Id: print('found edge/ length : ' + str(aedges[ii].Length) + 'Centre : ' + str(aedges[ii].Centroid)) return aedges[ii].Length break bodies = ExtAPI.DataModel.Project.Model.GetChildren(DataModelObjectCategory.Body,True) for body in bodies: print(body.Name) gbody = body.GetGeoBody() faces=gbody.Faces for i in range(len(faces)): for j in range(i + 1, len(faces)): compare(faces[i], faces[j])
0