Error 000582 - "Export to PDF" causing problems with "Select by Attribute"??

852
4
03-20-2013 02:21 PM
MattSimonds
New Contributor
I've created a python script that manipulates a page layout so that I can export the view to a PDF.  The code uses several different ""Select By Attribute" methods.

My code operates as a function in a module I import into the arcpy window.  After executing the function a number of times (variable number - say between 5 and 20) the following error is returned
[ATTACH=CONFIG]22815[/ATTACH]
Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000582: Error occurred during execution.

The code section that causes the error is:
    ##Highlight correct SU in extent window
    df = arcpy.mapping.ListDataFrames(mxd, "Legend and Extent Rectangle")[0]
    for lyr in arcpy.mapping.ListLayers(mxd, bldg, df):
        for sublyr in lyr:
            if sublyr.name == s:
                sublyr.visible = True
                arcpy.SelectLayerByAttribute_management(sublyr, "NEW_SELECTION", "[SU] = %d" % (SU))
            else:
                sublyr.visible = False


Under geoprocessing options, I turned OFF background processing because simple selection like the one above take FOREVER with background processing turned on. (Side question - why must the map refresh after every selection?  Can I supress that??)

I noticed however that if I turn background processing ON, I can run my code again without a problem.  Does anyone have an idea what is causing this problem, and why it might be so seemingly random?
Tags (2)
0 Kudos
4 Replies
MathewCoyle
Frequent Contributor
How do you define your mxd variable? Are you using the 'current' keyword by any chance?

Edit: Actually no that shouldn't cause issues how you are executing it. When you get the errors do they come up as soon as you try to execute it or does it process or a bit? Are you sure your layers are all groups and all have sublayers?
0 Kudos
MattSimonds
New Contributor
Yes I am:

mxd = arcpy.mapping.MapDocument("CURRENT")
0 Kudos
MathewCoyle
Frequent Contributor
Your code will generate an error when there is a non-group layer in your data frame, I would check that.

Edit: It could also have to do with running it as a model instead of a script.

'If you open the ModelBuilder window and run a model, all processes in the model execute in the foreground. Working in the ModelBuilder window is similar to an edit session. Any processes run do so in the foreground to prevent a situation where changing the workflow could cause undesirable results.'

From here.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00210000003q000000
0 Kudos
MattSimonds
New Contributor
Thank you for the suggestions.  Unfortunately in this case I only run the code on one specific mxd which has the necessary group layers, and I am not running in model builder, but rather in the python window. (because this isn't a distributed code, I'm not worried about someone using it with another mxd)
0 Kudos