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?

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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.