Anyone tried access label properties trough ArcObjects with Python?
I try to obtain reference to label object with IAnnotateLayerPropertiesCollection2.QueryItem, but when I do:
pA = pGLyr.AnnotationProperties
new = NewObj(esriCarto.LabelEngineLayerProperties,esriCarto.IAnnotateLayerProperties)
pA.QueryItem(0,new)
I get: Runtime error : call takes exactly 2 arguments (3 given)
I'm not sure where is the error comming from.
Any ideas?
1 Answer 1
In comtypes, out arguments are returned as a tuple, they do not need to be passed in to the function. From the comtypes home page:
Calling methods
Calling COM methods is straightforward just like with other Python objects. They can be called with positional and named arguments.
Arguments marked
[out]
or[out, retval]
in the IDL are returned from a sucessful method call, in a tuple if there is more than one. If no[out]
or[out, retval]
arguments are present, theHRESULT
returned by the method call is returned. When[out]
or[out, retval]
arguments are returned from a sucessful call, theHRESULT
value is lost.If the COM method call fails, a
COMError
exception is raised, containing theHRESULT
value.
This works for me:
def enumerate_anno_properties(layer):
gfl = CType(layer, esriCarto.IGeoFeatureLayer)
if gfl:
annoProps = gfl.AnnotationProperties
for i in range(annoProps.Count):
yield (CType(annoProps, esriCarto.IAnnotateLayerPropertiesCollection2)
.QueryItem(i))[0]
-
Cool, works great. I would not think of generator use.Tomek– Tomek2013年08月07日 14:17:12 +00:00Commented Aug 7, 2013 at 14:17