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)

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, the HRESULT returned by the method call is returned. When [out] or [out, retval] arguments are returned from a sucessful call, the HRESULT value is lost.

If the COM method call fails, a COMError exception is raised, containing the HRESULT 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)
  • Cool, works great. I would not think of generator use.
    – Tomek
    Aug 7, 2013 at 14:17

Your Answer

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

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