If the case involves parents who are divorced the courts will look at the divorce settlement and the custody and visitation arrangements already made. In fact, the best time to get the courts to enforce your grandparents rights is often during a divorce when language asserting your grandparents visitation can be inserted into an agreement.
Do not be afraid to ask for this when a divorce is occurring. Often, if you are in a situation where the party with custody will end up being the party not related to you then you can seek to include grandparents visitation and it will be agreed to in the bargaining phase of the divorce.
Also see my post on when Grandparents Rights apply.
You can find out much more about this issue in my new book No Greater Loss: The Guidebook to Today’s Grandparents Rights