AnsweredAssumed Answered

Is it possible to use MakeFeatureLayer_management out of process?

Question asked by dkolbay on Apr 8, 2020
Latest reply on Apr 9, 2020 by dkolbay

Hello all and thanks in advance for reading through my question,

 

I'm writing a python script that is selecting features from a GDB feature class and using the attributes from the selected features during my analysis.  I'm eventually displaying a Tkinter form to the user that displays the results.  My script works fine if I run it outside of ArcMap in a command prompt but if I run it inside as a script tool (out of process) it fails. 

 

I have worked through launching a script from a toolbox and running it "out of process" (unchecked Run Python script in process) to display the Tkinter form.  As long as I don't need to use MakeFeatureLayer_management, my form launches, displays results, and behaves as expected.  But since I need to create a layer from the GDB feeature class to be able to select features, I am running into the problem.  The resultant layer from MakeFeatureLayer_management causes the script to fail if it is run out of process which is needed if I want to display a Tkinter form.  

 

The code below should be able to recreate the problem I am having.

  • Run it from the command line - prints the spatial reference name twice
  • Run from a script tool with "Run Python script in process" checked - outputs the spatial reference twice
  • Run from a script tool with "Run Python script in process" unchecked - crashes on line 8

 

import arcpy

myGDB = r'C:\Data\myGeoDatabase.gdb'
polyFeatureClass = ['Polys1', 'Polys2']

for i in range(0,len(polyFeatureClass)):
    polyLayer = arcpy.MakeFeatureLayer_management(myGDB + '\\' + polyFeatureClass[i], polyFeatureClass[i])
    sr = arcpy.Describe(polyLayer).spatialReference
    print(sr.name)
    arcpy.AddMessage(sr.name)

 

Any thoughts on what might be causing this and how I might be able to get around it?  Is there another method to select feature from the feature class?  I read what appeared to be a similar question posed in 2014 (https://community.esri.com/thread/104854) but the end solution was to run it outside of ArcMap.  I really want my users to be able to use the tool within ArcMap.

 

Thanks,

Damian

Outcomes