Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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;
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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: http://gis.stackexchange.com/a/5082/753

share|improve this answer
    
could you please write the cast code ? –  wetland Oct 6 '12 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 Oct 6 '12 at 20:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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