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'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
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
add comment

1 Answer

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
2  
the problem is it gets inactive. It doesn't work. –  Matt Jun 22 '12 at 5:41
add comment

protected by whuber Jul 18 '12 at 15:18

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

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.