Select to view content in your preferred language

ArcToolbox Error

748
5
08-16-2022 07:42 AM
JohnMedema
Occasional Contributor

my script is returning an error that I dont understand. (see image below)

code snippet:

LFTcode.png

 

 

LFT_Error.png

0 Kudos
5 Replies
Brian_Wilson
Honored Contributor

Your layer object has things in it that are not shape, so it's choking on that. It might be a group or a table?

To debug your error, start by looking up Describe in the docs to see how it's used. 

https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/describe.htm

Look at what it returns, it's just an object. That object can then have properties and methods.  So in theory your syntax could work if Describe returns an object with the property "shapeType" but it's not. 

Look at what it's returning in that docs page, it will be an object of type "Describe". 

It can return any of about 30 different things. If it's not returning a feature object it won't have a shape. Also it could be returning a NULL. You might want to use a try / except block to handle those cases.

f = "unknown thing"
try:
  d = arcpy.Describe(thing)
  f = d.featureType
  shape = d.shapeType
except Exception as e:
  print("This is a", f)
  print(e)

 

The error message is a little confusing because Python thinks shapeType is a method, it would really be a property. But whatever, there is no shapeType defined on whatever object being returned by Describe for that input.

 

JohnMedema
Occasional Contributor

Thank you for your input. I added some of your text to my script and ran it in the python window.  As you can see the print(arcpy.Describe(lyr).shapeType returns the point layers (sourced from my company portal) and the Polygons (all fgdb feature classes from separate fgdbs).  When I print(shape) I only get the polygon layers in my map.  Here is a snippet from my python window

ESRIForum.png

0 Kudos
Brian_Wilson
Honored Contributor

Okay, when you look at FeatureLayers only, they all have a shapeType --- that's what I would expect. In your first example you did something like this, this will probably fail --

aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.listMaps()[0]
for lyr in mp.listLayers():
  d = arcpy.Describe(lyr)
  print(d.shapeType)

In the second one you did something more like this,

aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.listMaps()[0]
for lyr in mp.listLayers():
  d = arcpy.Describe(lyr)
  if d.dataType == "FeatureLayer":
    print(d.shapeType)

 

My copy of ArcPro crashes on this code, because I have some layer in my map that it really hates, I think it's an external service. I have to go home now, but I will try it in Visual Studio Code tomorrow which is less prone to crashing. By the way IDEs are great, I use Visual Studio Code, but many people prefer Spyder. They let you examine the values of objects without having to keep writing print() statements.

JohnMedema
Occasional Contributor

I appreciate the help.  I actually got the tool to run through successfully yesterday. Oddly, no error was received.  I am trying to get a license for Microsoft Visual through my company's SOP.  So, that will likely take some time.

0 Kudos
Brian_Wilson
Honored Contributor

"Visual Studio Code" is free.

https://code.visualstudio.com/

There are community (free) and  commercial versions of "Visual Studio" but that is  totally different products. I used it for years as a C# programmer and later for Python but I think that VS Code is much better for Python and Javascript. I have not used it for C#. I use it for pretty much any text files these days, there are formatters for just about everything. It handles remote editing too, so, I can maintain projects that run on servers from my desktop.

 

0 Kudos