AnsweredAssumed Answered

How to add Symbology to a Feature Class??

Question asked by Adamarcichowski on Mar 30, 2019
Latest reply on Mar 30, 2019 by Adamarcichowski

I don't understand how to add a simple symbology to a feature class created in the the script and add it to a new map. Well I kind od did figure it out but this my code seems ridiculously long just to add symbology from a existing layer.

 

I thought up to line 21 would be good enough to set the symbology I need. However, i had to add line 22,23,24 to get what I want. 

 

Basically I want the user to enter in a feature class, set a SQL expression and isolate the feature they want. Take that feature save it, add it to a different mxd, apply the symbology from an existing layer and save the mxd. 

 

I've heard of Derived and SetOutputParameters and apply the symbology there but I dont understand how to write that in the code. 

 

import arcpy, datetime, os, sys, string
date = datetime.datetime.now()
namefile = arcpy.GetParameterAsText(0)
prjbdy = arcpy.GetParameterAsText(1)
express = arcpy.GetParameterAsText(2)
mxdpath = "C:\Users\Adam\Desktop\Test5.mxd"

arcpy.CreateFileGDB_management(namefile, "\\SlopeAdam" + date.strftime("%Y%m%d")+ ".gdb")
fgdb = namefile + "\\Slope" + date.strftime("%Y%m%d")+ ".gdb"
arcpy.env.workspace = fgdb


mxd = arcpy.mapping.MapDocument(mxdpath)
df = arcpy.mapping.ListDataFrames(mxd)[0]

arcpy.MakeFeatureLayer_management(prjbdy, "prjbdy_Layer",express)
arcpy.CopyFeatures_management("prjbdy_Layer", "test3")
arcpy.MakeFeatureLayer_management("test3", "test4")
arcpy.ApplySymbologyFromLayer_management('test4', "C:\Users\Adam\Desktop\SlopeAnalysis\prjbdy_Layer.lyr")
arcpy.SaveToLayerFile_management('test4',"C:\Users\Adam\Desktop\SlopeAnalysis\prjbdyoutada")
addLayer = arcpy.mapping.Layer('test4')
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.AddMessage("Finished Adding raster & applying symbology.")


mxd.save()
del mxd

 

 

Thanks! 

Outcomes