Ansys Learning Forum Forums Discuss Simulation 3D Design Discovery Getting the Circle centers form Named selection Reply To: Discovery Getting the Circle centers form Named selection

Atharv Joshi
Forum Moderator

Hi Erkki, 

I was trying this and currently was able to write a script without using named selection. It uses perimeter range to filter out the circular edges and then measure the co-ordinates for the center of the holes. 

list=[]
all_bodies=GetRootPart().Bodies
for body in all_bodies:
    for i in body.Edges:
        ##I am using 0.0157-0.0158 range to filter out edges based on perimeter for the 5mm hole I have in my CAD
        ##Change it according to the hole diameter you have. 
        if i.Shape.Length >0.0157 and i.Shape.Length <0.0158: ##Units are in Meter for script so its 0.0157
            list.append(i)
            
    centre_cordinates=[]
    for i in list:
        centre=[]
        # Measure x
        selection = Selection.Create(GetRootPart().CoordinateSystems[0])
        secondarySelection = Selection.Create(i.GetChildren[ICurvePoint]()[0])
        gap = MeasureHelper.DistanceBetweenObjects(selection, secondarySelection)
        deltaX = gap.DeltaX
        # EndBlock
 
        # Measure y
        selection = Selection.Create(GetRootPart().CoordinateSystems[0])
        secondarySelection = Selection.Create(i.GetChildren[ICurvePoint]()[0])
        gap = MeasureHelper.DistanceBetweenObjects(selection, secondarySelection)
        deltaY = gap.DeltaY
        # EndBlock
 
        # Measure z
        selection = Selection.Create(GetRootPart().CoordinateSystems[0])
        secondarySelection = Selection.Create(i.GetChildren[ICurvePoint]()[0])
        gap = MeasureHelper.DistanceBetweenObjects(selection, secondarySelection)
        deltaZ = gap.DeltaZ
        # EndBlock
        centre.append(deltaX)
        centre.append(deltaY)
        centre.append(deltaZ)
        centre_cordinates.append(centre)
 
print(centre_cordinates)

 

I will further check this with named selection as input. You can also try to explore further. 

Thanks and Regards
Atharv

Â