Using Arc 10.2
I am getting the following error message...
ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Layer: Dataset Q:\Data\Infrastructure\Infrastructure.gdb\LiftStations_Active does not exist or is not supported Failed to execute (ApplySymbologyFromLayer).
...when I run a script containing the following code snippet:
dest = arcpy.GetParameterAsText(1)
destWorkspace, destName = os.path.split(dest)
arcpy.FeatureClassToFeatureClass_conversion(source, destWorkspace, destName, "", mapping)
in_symbology_layer = r"Q:\Data\lyrfiles\LiftStations.lyr"
arcpy.ApplySymbologyFromLayer_management (dest, in_symbology_layer)
There are no problems with the first four lines of my snippet (all the parameters are legit and I'd rather spare you the entire or extraneous sections of my code). The error message says nothing about those lines and I've confirmed the "in_symbology_layer" exists (Q:\Data\lyrfiles\LiftStations.lyr).
I have double checked - the FC mentioned in the above error message does exist. In fact, since it comes directly from the tool's 2nd GetParameterAsText, the tool warns me that it "already exists" with the exclamation symbol beside the parameter field.
Why am I getting this error?
Further Thoughts
Am I not allowed to use "ApplySymbologyFromLayer_management" on a Feature Class? On a newly-created FC?
Does it have anything to do with the fact that since "dest" is an Output Parameter it gets deleted as soon as the script begins? (reference: "Why is "arcpy.GetParameterAsText" deleting Target Feature Class?")
Does it have anything to do with the fact that "dest" then gets recreated only two lines prior to 'ApplySymbologyFromLayer_management'?
2 Answers 2
Symbology applies to a layer, not to a feature class. From the help:
This tool applies the symbology from a layer to the Input Layer. It can be applied to feature, raster, network analysis, TIN, and geostatistical layer files or layers in the ArcMap table of contents.
You will need to make a feature layer within your code (the following is untested but should get you on the right track):
dest = arcpy.GetParameterAsText(1)
destWorkspace, destName = os.path.split(dest)
arcpy.FeatureClassToFeatureClass_conversion(source, destWorkspace, destName, "", mapping)
arcpy.MakeFeatureLayer_management (dest, "out_layer")
in_symbology_layer = r"Q:\Data\lyrfiles\LiftStations.lyr"
arcpy.ApplySymbologyFromLayer_management ("out_layer", in_symbology_layer)
You have too many backslashes in your path to your layer file. r
means raw string, so no need for \\
when you use r
in_symbology_layer = r"Q:\GW\EC1210WQAEH_QESEA\CSSP_ATL\Data\lyrfiles\LiftStations_NB_Active.lyr"
destWorkspace+destName
looks suspicious. Try:
import os
arcpy.ApplySymbologyFromLayer_management (os.path.join (destWorkspace, destName), in_symbology_layer)
-
The problem still exists in case you have any further ideas?Waterman– Waterman2018年07月16日 23:34:22 +00:00Commented Jul 16, 2018 at 23:34
Explore related questions
See similar questions with these tags.
r
removed. Or alternatively, undouble all your double slashes and leave ther
in place.