Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As for question, I am trying to adjust Grid Map labels via Arcobjects with Python. For now I do have:

from comtypes.client import CreateObject, GetModule
import arcpy

def CType(obj, interface):
   """Casts obj to interface and returns comtypes POINTER or None"""
       newobj = obj.QueryInterface(interface)
       return newobj
       return None

def NewObj(MyClass, MyInterface):
   """Creates a new comtypes POINTER object where\n\
   MyClass is the class to be instantiated,\n\
   MyInterface is the interface to be assigned"""
   from comtypes.client import CreateObject
       ptr = CreateObject(MyClass, interface=MyInterface)
       return ptr
       return None

esriCarto = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.0\com\esriCarto.olb")
esriCartoUI = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.0\com\esriCartoUI.olb")
esriMapUI = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.0\com\esriArcMapUI.olb")
esriFrame = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.0\com\esriFramework.olb")


pApp = NewObj(esriFrame.AppROT, esriFrame.IAppROT).Item(0)
pDoc = pApp.Document
pMxDoc = CType(pDoc, esriMapUI.IMxDocument)
pLayout = pMxDoc.PageLayout
pGraphContLayout = CType(pLayout, esriCarto.IGraphicsContainer)
iFrameElement = pGraphContLayout.FindFrame(pMxDoc.ActiveView.FocusMap)

As far as I understand, iFrameElement is an interface of an abstract class from which I need to inherit attributes (pointer) to MapFrame object. How do I do that? How do it get to object with IMapGrids interface. Any suggestions?

share|improve this question
up vote 1 down vote accepted

I did ask this question also at SO site (question at SO). Code sample is below:

pGraphContLayout = CType(pLayout, esriCarto.IGraphicsContainer)
pFrame = pGraphContLayout.FindFrame(pMxDoc.ActiveView.FocusMap)
pGrids = CType(pFrame, IMapGrids)
share|improve this answer
Yeah you just need to cast/QI between interfaces implemented by the class. I would strongly suggest reading the ArcObjects SDK conceptual help and object model diagrams before setting out to do anything with Python and comtypes which don't have the static typing and intellisense/pre-compilation warnings of a compiled language like C#. – blah238 Sep 7 '12 at 21:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.