AnsweredAssumed Answered

Different behavior in python scripting

Question asked by Alberto on Oct 14, 2015
Latest reply on Oct 15, 2015 by Alberto

Hi all,

I've written a script in which I analyze the TOC content in a selected map document. The analysis produces a list of datasets (table, shapefile, geodatabase fc, raster, mosaic dataset, etc...) in the TOC. If a dataset has missing datasource the information will be also reported.


Python code:

import arcpy

# [.....]

mxd = arcpy.mapping.MapDocument(mxdFilePath)

# [.....]

dtfs = arcpy.mapping.ListDataFrames(mxd)

for dtf in dtfs:

       for dts in arcpy.mapping.ListLayers(mxd, "", dtf):

               if dts.supports("DATASOURCE"):

                       if not arcpy.Exists(dts.dataSource):

                               file.write("\t  Missing datasource!  \n")


                               # do something.............

So I've created a Toolbox (tbx), added the script e run it: everything works well.

I've also embedded that script in a Python Toolbox (pyt) and run it: everything works well but Personal Geodatabase feature classes return always a "missing datasource" message, althought the data exist and datasources are correctly set.

Finally, If I run the pyt script as shown here, again everything works well.


So, I do something wrong in my Python Toolbox..... but what? Any help please?

Using Python 2.7.2 and ArcGIS 10.1.

Thanks in advance