1

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"""
 try:
 newobj = obj.QueryInterface(interface)
 return newobj
 except:
 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
 try:
 ptr = CreateObject(MyClass, interface=MyInterface)
 return ptr
 except:
 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")
arcpy.SetProduct('Arcinfo')
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?

asked Aug 29, 2012 at 10:54
0

1 Answer 1

1

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)
answered Sep 7, 2012 at 20:33
1
  • 1
    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#. Commented Sep 7, 2012 at 21:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.