I have a stand alone script that I am simply trying to get a record count from a layer in an mxd. I continue to get '-1' as the output with a layer that has 1200+ records. The data source is an SDE feature class within a feature dataset. When I try to print the data source I only get the name of the feature dataset and the feature class. I think the issue is because of this? I need to have the complete path seeing as this script will be run by other people on their own machines. Here is the portion of the code that prints the data source and tries to get the count:
import arcpy
mxd_path = r'C:\Projects\Test2.mxd'
mxd = arcpy.mapping.MapDocument(mxd_path)
df = arcpy.mapping.ListDataFrames(mxd)[0]
layer = arcpy.mapping.ListLayers(mxd, 'Test Boundary', df)[0]
print layer.dataSource
print int(arcpy.GetCount_management(layer.getOutput(0))
The first print statement returns
'/LAND.Boundaries/LAND.TestBoundary`
The second print statement returns
-1
The path and names of the mxd and layer are correct and exist. I think this is really weird that it won't include the sde connection file path with the layer.dataSource? I haven't found other answers to this specific problem I saw similar threads here
https://geonet.esri.com/thread/48767
However this only indicates using the describe with layer.dataSource. if I try to run any arcpy/geoprocessing on the layer it says this is not a valid parameter. For example I can't create a feature layer with MakeFeatureLayer_management with the layer returned in the stand alone script. I can run it in the Python command window successfully but unfortunately need to solve it for the stand alone script per my situation. Anyone seen this same issue of not returning the full path of the layer's data source?
print layer.workspacePath
to test?arcpy.Describe(layer).catalogpath
or importos
and tryos.path.abspath(layer)
. Does that provide anything?layer
variable is already a layer, so simplyprint arcpy.GetCount_management(layer)
should work. As to not getting the full data source path, I have layers in some mxds that behave the same way, but I'm not sure why. Try opening a new blank mxd and adding the layer giving you trouble (using the same connection, but don't drag it from the old mxd), and then run the script on that new mxd. Do you have the same issue, or is the full path returned?