0

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;
BBG_GIS
  • 5,825
  • 4
  • 45
  • 88

1 Answers1

2

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

blah238
  • 35,793
  • 7
  • 94
  • 195
  • could you please write the cast code ? – BBG_GIS Oct 06 '12 at 07: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 Oct 06 '12 at 20:07