megbers:
I assume you use a round something, maybe an edge finder, with near zero runout, or always use the same side of the something to do "touch off" to manually determine an edge.
Write five programs --- one each for left, right, rear, front, and calculate G5x. Touch one side and run its program, and repeat for each side. After all four sides are done run calculate.
Assign two variables for each axis, for example:
#500 is left X axis,
#501 is right X axis,
#502 is rear Y axis.
#503 is front Y axis.
Your programs could be O1001 for left, O1002 for right, etc, and O1000 for calculate. Note if you always made "front Y" the last program, then "calculate G5x" could be included in "front Y".
Program "left" would write the current X value of the machine into #500, and "right" the current X value into #501. Similarly for "front" and "rear".
"calculate" calculates the average of #500 and #501 and inserts this into the variable for X of G5x, and average of #502 and #503 into variable for Y of G5x, and you are done. You have to determine the correct signs and I leave the details to you.
.