How to use API to get the center coordinate value of a cylinder by selecting its edge?

How to use API to get the center coordinate value of a cylinder by selecting its edge?

For example, I want to get center coordinate value (0,30,0) in Fig1 or get center coordinate value (0,20,0) in Fig2.

Besides, generate a coordinate mark at the center at the same time. (Fig3 & Fig4)

[Fig1]

[Fig2]

[Fig3]

[Fig4]

SolidworksApi macros