What is causing my ArcGIS Pro to crash when running this Python code through the Python Window in ArcPro?

256
3
12-10-2019 11:14 AM
Highlighted
New Contributor II

a

arcpy.management.SelectLayerByAttribute("(SHAPE_IN_CONTENTS)", "NEW_SELECTION", "LEASE_NAME LIKE 'ABC%'", None)



arcpy.management.CopyFeatures("(SHAPE_IN_CONTENTS)", r"C:\Data\GIS\Project\Python\Python.gdb\(SELECTED_SHAPE)", None, None, None, None)



arcpy.management.Dissolve("(SELECTED_SHAPE", r"C:\Data\GIS\Project\Python\Python.gdb\(SELECTED_SHAPE_DISSOLVE)", None, None, "MULTI_PART", "DISSOLVE_LINES")

‍‍‍‍‍‍‍‍‍‍

Shapefile name is within ( ) 

I can run each line separately. I can run 2-3 separately. Occasionally 1-3 work, 1-2 work, 2-3 works 100% of the time.

I'm wondering if I need to add code between line 2-3 to reference the file?

When I try to run the entire code, the trailling dots freeze and windows says ArcGIS Pro has stopped working

Tags (2)
Reply
0 Kudos
3 Replies
Highlighted
MVP Esteemed Contributor

See Error 999999 in arcpy after ArcGIS Pro Crashes  on how to format your code so it's more readable. One thing that I notice is your selection; I always create a feature layer or a table view first and make the selections against them...

Reply
0 Kudos
Highlighted
New Contributor II

So I tried this. It worked and it gave me the the details of the output and loaded onto into contents of the map. Why, when run again does it crash? I am just inputting the arcpy.makefeature layer... function, nothing else.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

If you are running it again without quitting and restarting your pro project, you're trying to create the feature layer again of the same name but that name space is already spoken for 'in_memory' which is where the feature layer is held.

It's not giving you an error to that effect?  

In the following code snippet I create a table view called 'tv' and make a selection against.  If I wanted to try this again in a python window in Pro, I'd run line 1 again but substitute 'tv2' for 'tv' and then substitute 'tv2' for 'tv' in line 4

arcpy.MakeTableView_management(centerlinesSource, 'tv')
select = 'JOINID is not null and AN_NAME is not null and AN_POSTDIR is not null'

arcpy.SelectLayerByAttribute_management('tv','NEW_SELECTION',select)

blah blah blah‍‍‍‍‍‍