- 论坛徽章:
- 0
|
源码:
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.1\com\esriCarto.olb")
esriCartoUI = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.1\com\esriCartoUI.olb")
esriMapUI = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.1\com\esriArcMapUI.olb")
esriFrame = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.1\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)
报错如下:
C:\Python27\ArcGIS10.1\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd.py" --multiproc --client 127.0.0.1 --port 56644 --file D:/PycharmProjects/untitled1/arcpytest/test2.py
pydev debugger: process 10636 is connecting
Connected to pydev debugger (build 139.1547)
{'offsets': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'names': ['VT_BOOL', 'VT_I1', 'VT_I2', 'VT_I4', 'VT_I8', 'VT_INT', 'VT_UI1', 'VT_UI2', 'VT_UI4', 'VT_UI8', 'VT_UINT', 'VT_R4', 'VT_R8', 'VT_CY', 'c_wchar_p', 'c_void_p', 'pparray', 'bstrVal', '_tagBRECORD'], 'formats': ['<i2', '<i1', '<i2', '<i4', '<i8', '<i4', '<u1', '<u2', '<u4', '<u8', '<u4', '<f4', '<f8', '<i8', '<u4', '<u4', '<u4', '<u4', [('pvRecord', '<u4'), ('pRecInfo', '<u4')]]}Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd.py", line 2217, in <module>
globals = debugger.run(setup['file'], None, None)
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd.py", line 1643, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:/PycharmProjects/untitled1/arcpytest/test2.py", line 30, in <module>
pApp = NewObj(esriFrame.AppROT, esriFrame.IAppROT).Item(0)
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\__init__.py", line 855, in __call__
return self.getter(self.im_inst, *args)
_ctypes.COMError: (-2147352565, '\xce\xde\xd0\xa7\xcb\xf7\xd2\xfd\xa1\xa3', (None, None, None, 0, None))
这个错误谁能给点指导!谢谢!
|
|