The grid is nothing but notes on a drawing sheet format. SolidWorks doesn't know anything about the grid. Your drawing template may be set up with a grid or with no grid at all.
Therefore, there is no direct SolidWorks function for getting a dimension's location with respect to the grid. You would have to write a fairly extensive macro to read the sheet format, figure out what the grid is, then figure out which section of the grid your dimension is in.
It would be sightly easier to hard-code your grid locations for the different paper sizes into the macro. The macro would then find the paper size, get the X-Y location of the dimension, and compare it to the appropriate grid divisions.
Thanks Josh for such a detailed description. Let me try the approach you have mentioned and i will try to come back with the solution here.
Here is the code i wrote for getting the Grid location for an selected element on drawing sheet.
public String getGridLocation(Annotation swAnn)
dynamic swPoint = swAnn.GetPosition();
double xPoint = swPoint * 1000;
double yPoint = swPoint * 1000;
// A0 - 1188 * 840 mm
// Each number block is of size 49.5 and i have a total of 24 blocks on x axis ( 1 to 24 )
int xAxis = (int)Math.Ceiling(xPoint / 49.5);
// On Y axis i have "A to P" but they are in reverse direction to the Origin point. I had to offset the selection point for Y axis since by 15 for the space left on top side of the sheet.
int yAxis = 16 - (int)Math.Floor((yPoint + 15) / 50);
char yAlpha = Convert.ToChar(yAxis + 65);
String SheetNumber = getSheetNumber(); // My custom function
String location = SheetNumber + ", " + Convert.ToString(yAlpha) + Convert.ToString(xAxis);
// output eg: SH1 - C7
// just make some adjustments for other sheet sizes and it should work.