Python Script Works in IDLE but Fails in Pro

1816
5
12-28-2018 09:46 AM
deleted-user-1_r2dgYuILKY
Occasional Contributor III

I've been dealing with this issue for a couple of months. I have a Python script that converts CAD files to Geodatabase feature classes for nearly 100 facilities. The script runs flawlessly every time in IDLE 2.7.13. When I run the script in a toolbox in ArcGIS Pro 2.2.4, at least half the time the script fails at some point. It's usually on the tools arcpy.AddField_management (error 000852) or arcpy.Merge_management (error000735) . When the script does run to completion in Pro, the resulting feature classes are different from those generated by the standalone script. There are many null features, and/or data is copied from one DWG record to dozens of other features. I believe these errors are caused by record IDs not being correctly copied from a room report CSV using the   arcpy.TableToTable_conversion tool. 

I've made sure the script is Python 3 compatible and run the Analyze Tools for Pro tool with no errors. The only differences between the two versions of the script are arcpy.AddMessage functions in place of "print" and hardcoded paths in the standalone version versus arcpy.GetParameterAsText parameters in the ArcGIS Pro toolbox. 

Is anyone else having these kinds of problems with ArcGIS Pro? I'm OK with using the standalone script, but I want others to be able to use the tool in Pro. One hypothesis I have is that the script could be failing because ArcGIS Pro is open during the process, possibly due to memory errors. A few times when I have run the standalone script with Pro open and tried to refresh the geodatabase, the standalone script will error out. 

Tags (1)
0 Kudos
5 Replies
ErikLash1
Occasional Contributor

Don't mean to state the obvious but Idle 2.7.13 is Python 2.7 from ArcGIS Desktop and Idle (ArcGIS Pro) uses Python 3.6.5., two stated incompatible versions of Python.

Analyze Tools for Pro is a surface level tool. It does not work so well on complex scripts. Has a success rate about on par with 2to3 (not great) and doesn't patch most scripts well enough to create any semblance of true interoperability between Py 2 and Py3.

In my case, re-writing the code by hand after debugging did the trick for errors similar to yours. Found that I had to implement a bunch of try and except statements to get around incompatibilities between 2 and 3 that don't get caught by "Analyze Tools for Pro" 

deleted-user-1_r2dgYuILKY
Occasional Contributor III

Right. Hopefully ESRI will work on making that "Pro" tool more than a useless surface level thing. I won't hold my breath. This script was developed by my predecessor as an ArcMap 10.5 toolbox before anybody had installed Pro. I've been trying to port it over with limited success. 

I'll add try/except statements and see if that helps. Honestly I could care less about running this in a toolbox in Pro, but I need to be able to make it accessible to other people in my organization. I've always found it better to run Python scripts that use arcpy from IDLE or the command line instead of inside ArcMap. 

0 Kudos
DrewFlater
Esri Regular Contributor

Analyze Tools For Pro runs Python2to3 to determine syntax updates to make, and this is the best available automated method from the Python community to see the changes required to run code written for Python 2 in Python 3. Analyze Tools For Pro also performs simple checks for arcpy functions or modules that are not available in ArcGIS Pro.

These two checks have been very successful in getting many scripts written for ArcMap to work in ArcGIS Pro, but additional things not captured by the tool could definitely be encountered. However, we haven't heard about anything specific through tech support or other forum posts.

If there are specific things you have found that require try excepts to get it to work in ArcMap and Pro, please post it here and the Python experts can evaluate and give feedback (and we can potentially integrate such logic into the Analyze tool).

Thanks,

Drew 

DrewFlater
Esri Regular Contributor

Regarding problems with AddField, Merge, or TableToTable when running the script from Pro, would it be possible for you to get in touch with tech support on this problem? It sounds like a severe bug that we'd like to have analyzed by tech support and sent to development to fix the issue. You could also post the failing script and some sample data here if you have a set of steps that consistently shows the problem. Thanks

0 Kudos
deleted-user-1_r2dgYuILKY
Occasional Contributor III

So after sharing this with tech support it turns out that this is indeed a bug in ArcGIS Pro:

BUG-000120032: ArcGIS Pro does not recognize XREF layer in the AutoCAD file

0 Kudos