2

I have code that doesn't work at the moment:

# Import arcpy module
import arcpy
# Script arguments
Input = arcpy.GetParameterAsText(0)
if Input == '#' or not Input:
 Input = "frame" # provide a default value if unspecified
Symbology = arcpy.GetParameterAsText(1)
if Symbology == '#' or not Symbology:
 Symbology = "symbology" # provide a default value if unspecified
### Local variables:
Rearrange = Symbology
line_connection_shp = Rearrange
### Process: Apply Symbology From Layer
arcpy.ApplySymbologyFromLayer_management(Input, Symbology)
Process: Points To Line
arcpy.PointsToLine_management(Rearrange, line_connection_shp, "MMSI", "", "NO_CLOSE")

What this is doing is applying my layer symbology (a .lyr file) to a shapefile.

This results in an error:

ERROR 000732: Input Layer: Dataset C:\temp\test.shp does not exist or is not supported.

It works fine when I apply these tools myself, but creates errors while using it in Python.

This must be an issue with trying to input a shapefile into the ApplyFromSymbology tool, so is there a way to use a shapefile with that tool?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Apr 26, 2015 at 2:30

1 Answer 1

2

You are not providing the code required to add a layer to the map at all.

You need a feature layer from the shapefile and then save it on disk as the .lyr file.

inputLocationsSavedFcFeatLyr = arcpy.MakeFeatureLayer_management(input_locations_fc,"Stops")
arcpy.SaveToLayerFile_management(in_layer=inputLocationsSavedFcFeatLyr,
 out_layer=r"C:\GIS\LocationPoints1.lyr",
 is_relative_path=None,version=None)

Specify the template layer (with symbology you want to be applied) + apply it:

locationsTemplate_layer = mp.Layer(r"C:\GIS\LocationPoints1.lyr")
arcpy.ApplySymbologyFromLayer_management(locationsTemplate_layer,r"C:\GIS\LocationPointsTemplate.lyr")

Now you can add the .lyr file to the map document (here, it is added to a group layer):

mp.AddLayerToGroup(df, targetGroupLayer, locationsTemplate_layer)

More help docs on that is here:

answered Apr 26, 2015 at 5:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.