Hi,
I wrote some code to copy feature classes from one gdb to another.
Everything runs fine through python, but it fails when I try adding it to a python caller - Specifically, it crashes ArcGIS Application. I have no idea what’s going wrong as I get no error message, only this screen:
The odd part is that it manages to delete a layer and then copy the new one across before crashing:
Here’s the code i’m trying to run. Apologies in advance for the mess, it’s not my strong point!
import fme
import fmeobjects
import arcpy
import os
import fnmatch
from arcpy import env
class FeatureProcessor(object):
"""Template Class Interface:
When using this class, make sure its name is set as the value of the 'Class to Process Features'
transformer parameter.
"""
def __init__(self):
"""Base constructor for class members."""
pass
def has_support_for(self, support_type: int):
"""This method is called by FME to determine if the PythonCaller supports Bulk mode,
which allows for significant performance gains when processing large numbers of features.
Bulk mode cannot always be supported.
More information available in transformer help.
"""
return support_type == fmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM
def input(self, feature: fmeobjects.FMEFeature):
"""This method is called for each feature which enters the PythonCaller.
Processed input features can be emitted from this method using self.pyoutput().
If knowledge of all input features is required for processing, then input features should be
cached to a list instance variable and processed using group processing or in the close() method.
"""
arcpy.env.workspace = r"C:/Sewer_AssetPackage.gdb"
outGDB = r"C:/AssetPackage7.gdb/"
fcs = arcpy.ListFeatureClasses()
tables = arcpy.ListTables()
ds_list = arcpy.ListDatasets()
for fc in fcs:
arcpy.Delete_management(outGDB+fc)
print("{0} has been deleted".format(fc))
arcpy.management.Copy(fc, outGDB+fc)
print("{0} has been copied".format(fc))
for t in tables:
if t == 'WINGS_RELATIONSHIPS':
arcpy.Delete_management(outGDB+t)
print("{0} has been deleted".format(t))
arcpy.management.Copy(t, outGDB+t)
print("{0} has been copied".format(t))
for ds in ds_list:
for FC in arcpy.ListFeatureClasses("*","",ds):
if ds == 'UtilityNetwork':
arcpy.Delete_management(outGDB+ds+'/'+FC)
print("{0}/{1} has been deleted".format(ds,FC))
arcpy.management.Copy(FC, outGDB+ds+'/'+FC)
print("{0}/{1} has been copied".format(ds,FC))
elif ds == 'SewerOther':
arcpy.Delete_management(outGDB+ds+'/'+FC)
print("{0}/{1} has been deleted".format(ds,FC))
arcpy.management.Copy(FC,outGDB+ds+'/'+FC)
print("{0}/{1} has been copied".format(ds,FC))
self.pyoutput(feature)
def close(self):
"""This method is called once all the FME Features have been processed from input()."""
pass
def process_group(self):
"""This method is called by FME for each group when group processing mode is enabled.
This implementation should reset any instance variables used for the next group.
Bulk mode should not be enabled when using group processing.
More information available in transformer help.
"""
pass
I read that someone had a similar issue (not in FME) and it was due to declaring the arcpy.env.workspace variable. When I remove this I have no idea how to use the list_featureclasses/datasets/tables/ function.
Any help would be much appreciated!
Many thanks,
Sam
Form version: 2023.1
Python version ESRI ArcGIS Python 3.7+/3.9