Runtime error Traceback - SelectLayerByAttribute

9730
13
Jump to solution
04-07-2015 11:47 AM
SilvanStöckli
New Contributor III

Hello

Every time I execute my python-script in the end it says

Runtime error  Traceback (most recent call last):   File "<string>", line 52, in <module>   File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 7211, in SelectLayerByAttribute raise e ExecuteError: ERROR 000229: Cannot open Rest\Kartenausschnitte A3 mit Aussparung Legende. 1:2500 und 1:3000 Failed to execute (SelectLayerByAttribute).

So this is the "bad" part of my script. lyrkartenausschn is "Rest\Kartenausschnitte A3 mit Aussparung Legende. 1:2500 und 1:3000"

cursor = arcpy.da.SearchCursor(lyrkartenausschn, [seitenzkartenausschn])

    seitenliste = int(19)

    del seitenliste

    seitenliste = []

    for row in cursor:

        seitenliste.append(int(row[0]))

    print seitenliste

    for seite in seitenliste:

        for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):

            if elm.name == seitex:

                elm.text = str(seite)

                pfdausgabePDFeinzeln = pfadausgpdf[0:-4] +"_"+ str(seite) + ".pdf" #Path

        arcpy.SelectLayerByAttribute_management (lyrkartenausschn, "NEW_SELECTION", seitenzkartenausschn + " = " +  str(seite))

        mxd.dataDrivenPages.exportToPDF(pfdausgabePDFeinzeln, "SELECTED") #PDF Export

        mxd.dataDrivenPages.printPages(druckername, "SELECTED") #  Print

    mxdspeicher = ausgpdfmxd + "\\" + bewirtschafter + ".mxd"

    mxd.saveACopy(mxdspeicher)

    del row

    del cursor

    del seite

    del seitenliste

    del elm

    arcpy.RefreshActiveView()

There's a lot of things I'm doing bevore. So if I leave the "bad" part, it loops trough the whole script perfectly. If I add this part, the error appears.

I also tryed to add the line "arcpy.SelectLayerByAttribute_management (lyrkartenausschn, "CLEAR_SELECTION")" at the verry bottom, but then the same error appears for this line.

So what's wrong with the code? do I have to del something more? or "deactivate" data driven pages? (maybe it's a problem because it's still printing? but then how can I make it wait until it's finished?

thank you for your help!

0 Kudos
13 Replies
XanderBakker
Esri Esteemed Contributor

This may be difficult to solve without the data and only part of the code. If the problem is caused by an access error of the layer contained in variable "lyrkartenausschn", you should have a look at how the layer is defined (this part is not included in the code posted).

I also came across this issue: 43104 - 000229: Cannot open  which indicates that if you have background processing switched on, it may cause this problem.

SilvanStöckli
New Contributor III

Thank you so much!

I had backgroundprocessing turned on. So now I switched it off and it works.

I'm so happy

0 Kudos
XanderBakker
Esri Esteemed Contributor

Congratulation, glad it fixed it!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Great catch!  I reached a point where Background Processing was giving me enough headaches that I started moving more towards scripting ArcPy outside of ArcGIS Desktop. 

0 Kudos