I use ArcObject in python to develope a tool. I import comtypes in python to access the arcmap layers in python and use ifeaturelayer interface. I have to set featurelayer to phookhelper.focusmap.get_layer(i) to access the layers in ArcMap. The problem is that I can't find get_layer method in python. Is there any way to access the ArcMap layers in python using ArcObjects?

for (int i = 0; i < phookhelper.FocusMap.LayerCount; i++)
                if (phookhelper.FocusMap.get_Layer(i).Name == comboBox1.Text)
                    pfeaturelayer = (IFeatureLayer)phookhelper.FocusMap.get_Layer(i);

                    pfc = pfeaturelayer.FeatureClass;

1 Answer 1


Try Layer[i] instead of get_Layer(i).

Instead of using IHookHelper you can get a reference to the ArcMap application, cast it to IMxApplication and then get its FocusMap.

More pointers here: http://www.pierssen.com/arcgis/upload/misc/python_arcobjects.pdf

Useful helper module here: https://gis.stackexchange.com/a/5082/753

  • could you please write the cast code ?
    – BBG_GIS
    Commented Oct 6, 2012 at 7:54
  • Like this: CType(pApp, esriArcMapUI.IMxApplication) where CType is a helper function defined in either of the above links, pApp is an IApplication reference, and esriArcMapUI is a reference to the comtypes.gen wrapper around the esriArcMapUI.olb library.
    – blah238
    Commented Oct 6, 2012 at 20:07

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.