4

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)
  pEnumLayer.Reset
  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
  Loop

Set pLayer = pMxDocument.SelectedLayer

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

End Sub
2
  • You're talking about replicating the functionality in right-click on layer in TOC > Selection > Make this layer the only selectable layer? Commented Jan 25, 2012 at 4:52
  • yes, exactly. TOC > Selection > Make this layer the only selectable layer
    – Mehdi
    Commented Jan 25, 2012 at 5:18

1 Answer 1

4

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.

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

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