3

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?

asked Aug 4, 2013 at 18:36

1 Answer 1

5

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)
 .QueryItem(i))[0]
answered Aug 4, 2013 at 20:08
1
  • Cool, works great. I would not think of generator use. Commented Aug 7, 2013 at 14:17

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.