0

I am trying to find out if an mxd contains any schematic diagram layer through a python script tool. I am looping through all the mxds those are added to the python script tool and in each mxd checking each layer whether it's a schematicdiagram layer or not.

My actual code in .py file looks like this:

import arcpy
mxdList = string.split(arcpy.GetParameterAsText(0), ";")
outXLSpath = arcpy.GetParameterAsText(1)

mxdCount = 0

for mxdpath in mxdList:
    if "'" in mxdpath:
        mxdpath = mxdpath[1:-1]
    else:
        mxdpath = mxdpath

    mxdCount = mxdCount + 1

    mxd = arcpy.mapping.MapDocument(mxdpath)
    (filepath,filename)= os.path.split(mxd.filePath)

    arcpy.SetProgressorLabel("Extracting Layers for " + str(mxdCount) + " of " + str(len(mxdList)) + " MXDs \"" + filename[:-4] + "\"... ")
    arcpy.AddMessage("Extracting Layers for " + filename + "..." )
    lyrList = arcpy.mapping.ListLayers(mxd)

    for lyr in lyrList:
        if not lyr.isGroupLayer:
            longNameList = lyr.longName.split("\\" or "//")
            if len(longNameList)>1:
                    descTemp = arcpy.Describe('\\'.join(longNameList[:-1]))
                    if (not descTemp.dataType == "GroupLayer") and descTemp.dataElementType == "DESchematicDiagram":
                        arcpy.AddMessage("Schematic Layer")

The above code is throwing error for group layer it encounters in the list of layers. Following is the error being encountered by the tool!!

Traceback (most recent call last):   File "C:\ANM\ArcGIS\Tools\MyTools\ExportLayerList3-1-Test.py", line 34, in <module>

descTemp = arcpy.Describe('\\'.join(longNameList[:-1]))   
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\__init__.py", line 1234, in Describe 
return gp.describe(value)   File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 374, in describe
self._gp.Describe(*gp_fixargs(args, True))) 
IOError: "Boundaries" does not exist Failed to execute (ExtractLayerList2)

.

surprisingly the same code is working fine if I test it in ArcMap's Python window.

Would someone highlight the issue and suggest the solution.

2
  • Could you please provide more details on which parameters you are using for arcpy.GetParameterAsText(0) etc? – Aaron Jul 3 '14 at 22:07
  • 1
    I am using arcpy.GetParameterAsText(0) just to read the list of mxd files those are selected as input for the tool to work on. The parameters for this are "Data Type = ArcMap Document", "Direction = Input" and "MultiValue = Yes" – Navin Jul 6 '14 at 4:12
3

You need to pass in the full file path name to the arcpy.Describe method. It looks like you are only passing in the layer name and without knowing where to go to look for the layer, it can't find it and is telling you that it doesn't exist. When using the python window, it knows the workspace in which to look. When using a script you either need to set the workspace or use the layer.datasource.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy