2

I'm trying to move some Python 2.7 scripts from ArcMap 10.4 to Python 3.4 and ArcGIS Pro 1.3.1. I'm having difficulty understanding why I cannot reference layers in the Table of Contents directly by name (see 1st screenshot). I am able to do this in ArcMap (see second screenshot).

There is exactly one address point selected in each environment and the layer is renamed in the table of contents to "addresspoints" in each environment.

I know I could just rewrite the script to use a "full path" to the layer OR set my arcpy.env.workspace (which in both cases here is NOT set to the Enterprise GDB where addresspoints lives) and use the full name of the feature class but I would very much like to understand why this isn't working and if it is by design or if it is a bug.

Error 000732 in ArcGIS Pro

No Errors here (ArcMap 10.4). ArcMap 10.4 with No Error

The code:

myLayer = 'addresspoints'
ftrCount = int(arcpy.GetCount_management(myLayer).getOutput(0))
ftrCount

The error:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 14999, in GetCount
    raise e
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 14996, in GetCount
    retval = convertArcObjectToPythonObject(gp.GetCount_management(*gp_fixargs((in_rows,), True)))
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Rows: Dataset addresspoints does not exist or is not supported
Failed to execute (GetCount).
1

This works as desired/expected when I try it in ArcGIS Pro (1.4.1)

enter image description here

I noticed that your ArcGIS Pro layer addresspoints was in a group layer called Addressing. When I first tested (in the same project/map as my test above) it worked no problem, so I ruled it out.

However when I retested in a new project and map I replicated the error. It appears that in ArcGIS Pro it wants you to specify the Group Layer name also.

enter image description here

The code (and errors) from my screenshot:

x = 'rivers'
xCount = int(arcpy.GetCount_management(x).getOutput(0))
print (xCount)
1
y = 'streets'
yCount = int(arcpy.GetCount_management(y).getOutput(0))
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 15820, in GetCount
    raise e
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 15817, in GetCount
    retval = convertArcObjectToPythonObject(gp.GetCount_management(*gp_fixargs((in_rows,), True)))
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Rows: Dataset streets does not exist or is not supported
Failed to execute (GetCount).

z = r'MyGroupLayer\streets'
zCount = int(arcpy.GetCount_management(z).getOutput(0))
print (zCount)
21

Try changing your myLayer to reference the Group Layer:

myLayer = r'Addressing\addresspoints'
ftrCount = int(arcpy.GetCount_management(myLayer).getOutput(0))
print (ftrCount)
  • This is how GP works. If its in a group layer, it needs it part of the name. if you drag a layer that lives in a group layer into a tool, it has the 'group layer name\layer name' – KHibma Feb 24 '17 at 17:58
  • @KHibma It's not clear when migrating tools from Desktop to Pro, as ArcGIS Desktop python window allows you to specify the layer without the group layer name. – Midavalo Feb 24 '17 at 18:00
  • I'm actually surprised that works (without explicitly having the GL name). The intellisense/drop down prefixs the layer with the group layer inside ArcMap. – KHibma Feb 24 '17 at 18:03
  • @KHibma have been using it that way for years... will be annoying to fix – Midavalo Feb 24 '17 at 18:04
  • Hey that fixes it. Thanks @Mid! and @KHibma I'm glad I asked the question. This should be included in any documentation for migrating scripts to Pro! I also learned another thing that is different in Pro. If nothing is selected in ArcMap the count is the total number of features in the layer (thus something I use error handling for). In Pro the number returned is zero! – jbchurchill Feb 24 '17 at 18:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.