I have a simple script to do the following: 1) convert an Excel file to a dBase file, 2) make an event layer from the dBase file, 3) convert the event layer to a feature class, and finally 4) apply symbology from a symbology layer. When I run this script in the Python window in ArcMap it works flawlessly every time (the result is that both the event layer and the new feature class are added to the Table of Contents). When I run it as a script tool it does successfully complete tasks 1-3, but it does not add the event layer or the feature class to the table of contents, and it throws the following error for applying symbology:
Traceback (most recent call last):
File "C:\Users\Karen\Desktop\script.py", line 13, in <module>
arcpy.ApplySymbologyFromLayer_management("trees", "trees_symbology.lyr")
File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\management.py", line 6951, in ApplySymbologyFromLayer
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset trees does not exist or is not supported
Failed to execute (ApplySymbologyFromLayer).
Does anyone know why it will work in the Python Script window but not as a script tool? Below is my script:
import arcpy
arcpy.env.workspace = "C:\Users\Karen\Desktop\Using Urban ArcGis\Assignment 3"
arcpy.env.overwriteOutput = True
arcpy.ExcelToTable_conversion("trees.xls", "trees.gdb", "trees")
arcpy.MakeXYEventLayer_management("trees.dbf", "POINT_X", "POINT_Y", "trees_points")
arcpy.FeatureClassToFeatureClass_conversion("trees_points", "Week5.gdb", "trees")
arcpy.ApplySymbologyFromLayer_management("trees", "trees_symbology.lyr")