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
December 1, 2023 at 12:08 pm
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
Â