Working on a Python script that does some routine table management of a couple of feature classes. In one step I define a table join and then export that to a GDB. When that runs, it will add it to the Geodatabase and also add the new Feature Class as a layer to the table of contents. It always adds to the top of the Table of Contents, but I need it to be added to the bottom as the last item.

The problem that I am running into is that in my code, I define several local variables using an index from the Table of Contents like old_sites = mapx.listLayers()[3]

If I have this hardcoded and a new layer is added to the top, this layer is no longer indexed at position 3, it's now 4, but the code won't know that.

Is there a way to change the default add position to the bottom?


2 Answers 2


Not knowing your full workflow but can you use the wildcard option and the name of the layer to get the one you want, listLayers ({wildcard})

help doc

A wildcard is based on the layer name and is not case sensitive. A combination of asterisks (*) and characters can be used to help limit the resulting list.

Example: old_sites = mapx.listLayers('your layer name here')[0]


If the drawing order of your layer is important to you, and you are not satisfied creating layer objects based on any drawing order then you also have an optional parameter named add_position available with the addLayer method of the Map class:

addLayer (add_layer_or_layerfile, {add_position})

add_position is:

A constant that determines the placement of the added layer or layers in a map.

  • AUTO_ARRANGE —Automatically places the layer or layers based on its layer weight rules and geometry.
  • BOTTOM —Places the layer or layers at the bottom of the TOC layer stack.
  • TOP —Places the layer or layers at the top of the TOC layer stack.

(The default value is AUTO_ARRANGE)

There is also an insertLayer method that uses a parameter named insert_position:

insertLayer (reference_layer, insert_layer_or_layerfile, {insert_position})

insert__position is:

A constant that determines the placement of the added layer or layers relative to the reference_layer.

  • AFTER —Inserts the new layer after or below the reference layer.
  • BEFORE —Inserts the new layer before or above the reference layer.

(The default value is BEFORE)


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