Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a script in Python 2.6 to make a button or a keyboard shortcut for "Make This The Only Selectable Layer". I came across the following VBA scripts on the net, but the problem is it's not working in ArcGIS 10. Can anyone help me with a Python script to do that?

Public Sub MakeLayerSelectable_Click()

  Dim pMxDocument As IMxDocument
  Dim pMap As IMap
  Dim pEnumLayer As IEnumLayer
  Dim pLayer As ILayer
  Dim pId As New UID
  Dim pFLayer As IFeatureLayer

  Set pMxDocument = Application.Document
  Set pMap = pMxDocument.FocusMap
  pId = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"
  Set pEnumLayer = pMap.Layers(pId, True)
  Set pLayer = pEnumLayer.Next
  Do While Not pLayer Is Nothing
    If TypeOf pLayer Is IFeatureLayer Then
        Set pFLayer = pLayer
        pFLayer.Selectable = False
    End If
    Set pLayer = pEnumLayer.Next

Set pLayer = pMxDocument.SelectedLayer

If TypeOf pLayer Is IFeatureLayer Then
  Set pFLayer = pLayer
    pFLayer.Selectable = True
End If

End Sub
share|improve this question
You're talking about replicating the functionality in right-click on layer in TOC > Selection > Make this layer the only selectable layer? – Chad Cooper Jan 25 '12 at 4:52
yes, exactly. TOC > Selection > Make this layer the only selectable layer – Matt Jan 25 '12 at 5:18

Use the customize option on your tools toolbar: enter image description here

Search for the 'Make This Layer Only Selectable Layer' command, drag to toolbar. enter image description here

This customization should be automatically saved to your 'Normal' template. AKA - it should work every time you open ArcMap.

I found out about this the other day, you can put pretty much anything on your toolbar, I really like the Export Map and the Page and Print Setup functionality in the toolbar.

share|improve this answer
+1 for using the built-in application functionality before trying to write code to do the same thing. – blah238 Jun 21 '12 at 19:21
Thanks for the your reasonable answer. But I have to tell that I knew this before. – Matt Jun 22 '12 at 5:39
the problem is it gets inactive. It doesn't work. – Matt Jun 22 '12 at 5:41

protected by whuber Jul 18 '12 at 15:18

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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