Is it possible to create a list of layers (residing in something like a menu) that can be selected and added to an mxd using arcpy.mapping. I've been using the bit of code below (there's someone I need to thank for this as I nabbed it from this site) to add a single layer. The code is within a Scripting Tool and is added to a toolbar as a Geoprocessing Tool.

import arcpy
import arcpy.mapping

#Data Location
parcels = r'P:\Mapping\Data\Land.gdb\Parcels\Parcels'

#Get the map document
mxd = arcpy.mapping.MapDocument("CURRENT")

#Get the data frame
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]

#Create new layer
parcelLayer = arcpy.mapping.Layer(parcels)

#Add the layer to the map at the bottom of the TOD in data frame 0
arcpy.mapping.AddLayer(df, parcelLayer, "TOP")

#Refresh things
del mxd, df, parcelLayer

I want to avoid creating a script for each dataset that I want to add programatically to an mxd, but I also want to stay within Python/arcpy as I have no business trying to do this within ArcObjects. Any help is appreciated.

  • 2
    What is you overall goal? Are you trying to create a utility that makes it easy for users (you or others) to just "point and click" layers from the menu, to add to a new MXD, and have the layers pre-symbolized, scale thresholds set up, etc? – RyanKDalton Jan 3 '13 at 18:05
  • 1
    And if that is your goal, consider simply creating a repository of layer files and show them how easy it is to drag and drop those layer files into your ArcMap window. – blah238 Jan 3 '13 at 18:12
  • Yes, I'm trying to make it easy for users to add layers. My current workplace has a rediculus amount of data and there are about 10 or so datasets that we use on a daily basis. The issue is we have to navigate through folders/subfolders/GDB's/Feature Datasets to get to them. It be awesome to have a simple menu with a list of datasets we can quickly add. The data does not need to be pre-symbolized or have scale thresholds. – dchaboya Jan 3 '13 at 18:14
  • Creating a repository would require us to make copies of data, which is not ideal as this data changes on a daily basis. – dchaboya Jan 3 '13 at 18:18
  • 4
    No it would not. A layer file does not store the data, it only references the data, and describes how it should be symbolized, labeled, etc. – blah238 Jan 3 '13 at 18:31

All this effort seems unnecessary. Consider instead creating a Folder Connection to a shared folder containing your workgroup's most frequently used layer files.

Create Folder Connection

It is then a simple matter of expanding the folder connection and dragging and dropping the desired layer(s) into your map document.

The one caveat to this is that I would recommend not using drive letters if you have mapped network shares to drive letters, as these may not exist or be the same for everyone (unless you are quite diligent in setting them up and do not have conflicting drive letters). Instead use the fully-qualified UNC path (e.g. \\server\folder\subfolder instead of X:\subfolder where X: is mapped to \\server\folder) in both the layer file itself and the folder connection.

  • 3
    I could not agree more with @blah238 because I know several large organisations (state govt and resources) that have been doing it this way for years to their satisfaction. One other caveat is that if you have a folder with hundreds of layerfiles with connections to ArcSDE then take care not to have your users create search indexes on that folder. It has been seen to exhaust available connections. – PolyGeo Jan 3 '13 at 22:46

I know what you are getting at, I've been intending to build the same thing. My plan is to use an Addon to make a toolbar with a combo-box dropdown that has all the layers I use frequently.

Then you can load up the addon and just click which layers you want to add for each map without having to navigate through the mess of network drives, geodatabases, etc,etc.

I don't know how to do it yet but I found this helpful:



While I totally agree with @blah238's suggestion, if you do decide to go through with building a custom data loading utility, I encourage you to check out my answer to Symbolizing Layers in PostGIS, where I detail some concepts that I implemented in an ArcView 3.x custom data loader.


At the moment this is only possible with the Java or the. NET SDK. The Code for listing layers and adding them to the mxd is nearly the same on all these customizing platforms. The point is, that arcpy does not support any UI Controls. With 10.1 ESRI introduced at least Python based Addins, but its still not possible to use rudimentary UI Controls such as Dropdown Lists or Comboboxes. For UI Customizing you have to take the way over ArcObjects and the SDKs.

We combined an enterp ise search index based on solr ( single search textbox) where you can search our metadata repository and add layers which are found. You can achieve a pretty similar thing by setting up an ArcGIS server search service and use the arcgis onboardenterprise search feature. I think that would helpmost of your users.

  • 1
    Not exactly true although I somewhat agree with the recommendation. You can create ComboBoxes that reside on a toolbar with Python Add-Ins, and you can also create custom GUIs with wxPython. – blah238 Jan 4 '13 at 9:31
  • Agree with blah238. Python Add-Ins are getting a step closer for allowing "real" customizations, but it's not quiet there yet. I thought I heard somewhere that there are some issues with using Python Add-Ins with GUI builders like tkinter/wxPython? – dchaboya Jan 4 '13 at 16:39
  • Thanks for the link blah! Even our ESRI Distributor didnt know that. As ESRI propagates python as their VBA follower, I think they have to improve their tooling for building GUIs with it and unleash the full power of python as an customizing platform. Lookingforward to 10.2 – Jürgen Zornig Jan 19 '13 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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