How can I use the arcpy.mapping.ListLayers()
function without calling the current mxd? I'm hoping to run the Python script without having an ArcMap document open.
My setsymbology code runs extremely slowly as it is now. I could do it faster manually, and my computer is definitely not the limiting factor. I'm guessing it's slow because ArcMap is open. I'll show the code as it is now and the code that I'm trying to figure out a way for it to call an input directory/workspace rather than an mxd, but unfortunately it gets errors ('module' object has no attribute 'Listlayers').
# Import system modules
import arcpy
from arcpy import env
mxd = arcpy.mapping.MapDocument("CURRENT")
symbologyLayer = r"C:\VMshared\small_example_valley3\SnowColor2\snowdepthCOLOR.tif.lyr"
for lyr in arcpy.mapping.ListLayers(mxd):
arcpy.ApplySymbologyFromLayer_management(lyr,symbologyLayer)
Best Answer
To your first question:
I would say the answer is to use something like:
in place of:
C:\temp\test.mxd does not need to be open and if you want to save changes to it use
mxd.save()
In answer to what your question became, there is a code sample in the Online Help which I abbreviated slightly. It appears to use the same coding pattern that you did in your answer: