soatley

addLayer very slow

Discussion created by soatley on Jul 13, 2011
Latest reply on Jul 20, 2011 by soatley
Greetings:

I'm trying to use addLayer to load several image files to the TOC. Here's the basic code:

import arcpy
import sys
import os.path

mxd = arcpy.mapping.MapDocument("CURRENT")
df= arcpy.mapping.ListDataFrames(mxd)[0]

dummy = "dummyImport.lyr"

names=['foo.sid','bar.sid']
for n in names:
    path = os.path.dirname(n)
    name = os.path.basename(n)
    addLayer = arcpy.mapping.Layer(dummy)
    addLayer.name = name
    addLayer.replaceDataSource(path,"",name)
    arcpy.mapping.AddLayer(df, addLayer, "TOP")


I run this as a script from a toolbox, and it takes 3-4 minutes to load a handful of layers. Am I missing something that would speed this up?

Thanks,
Scott

Outcomes