I've written a script using Arcpy.mapping module to automate map making. It works as a one-off for use in ArcMap if I use the ArcToolbox to call the script. But if I call it from python (eclipse) I get weird error messages ("ExecuteError: ERROR 000358: Invalid expression") pointing towards the "Select by Layer" tool. But it executes fine if run from ArcToolbox, no errors... same script.
Part 2: I gave up running it from Eclipse and ran it from ArcToolbox within ArcMap. Now I'm trying to run a batch - multiple maps. It used to work until this morning. this morning I made the most minor of changes... to check to see if a variable.upper() == 'YES'
again, this works in the "one-off" scenario within ArcMap called from ArcToolbox. But I'm trying to run my batch script (also called by ArcToolbox) and I get that same query error as above. Why is that? it's the exact same script. I don't want to interactively run this script in ArcMap for all 350+ maps. Why is arcpy.mapping so flaky? Is there a way to fix this???
p.s. I've uploaded the most recent version of the batch script and the other one.
minor changes included checking for upper case value for a text variable, changing a UNC path to a drive letter mapping, and adding a bunch of Add Message to see where it's bombing.
search for "check 1" "check 2" etc and you'll see... it doesn't get to check 6.
I think "ListLayers" returns a list. I'm assuming that you are only expecting one layer called "Dimensions" to be returned. Try changing this:
arcpy.mapping.UpdateLayer(dFrame, upLyr, srcLyr, False)
to this:
arcpy.mapping.UpdateLayer(dFrame, upLyr[0], srcLyr, False)
yea, you are missing an 0 index on a listlayers by check 3
arcpy.AddMessage("check 3")
#upLyr = arcpy.mapping.ListLayers(self.mxd, "Dimensions", dFrame)[0]
upLyr = arcpy.mapping.ListLayers(self.mxd, "Dimensions", dFrame)
i've tried both 0 and not 0 (i've taken turns commenting out one or the other one)
same result... bombs before check 6
if I leave the [0] in there I just got an error saying "list index out of range".
But I do have a layer called "Dimensions" in my mxd... I just double checked
I decided to close out ArcMap - re open ArcMap and now the error message has reverted back to the
"
ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).
"
very weird because other than re-activating the line upLyr = arcpy.mapping.ListLayers(self.mxd, "Dimensions", dFrame)[0]
I didn't do anything different. Seems so random.
I closed ArcMap again, re opened and now I'm back at the List Index out of range error for the updateLayer
How come your using this OO formatted python script?
Seems like a few added steps, for what may seem to cut time.
@ToddUlery
the idea was to utilize python to be able to send a batch of maps - 350+
it included lots of customization like truncating text fields, creating text files where it was truncated, adding text if it meets certain conditions, filtering out a layer, zooming to it, etc. Not all of those functions are readily available in Data Driven Pages yet.
as for OO formatting I'm still learning this stuff. I was told that programming best practices in python (or anything else) was to use modules, classes, etc
P.S. is there a way to order these replies by date? it's pretty confusing... I don't know where my last addition to this thread went to now.