I recently switched from Desktop to Pro and totally at a loss of figuring out how to make this very simple script work in ArcPro. Note that it runs and says success but the symbology does not change.
import arcpy
in_fc = arcpy.GetParameterAsText(0)
in_lyrx = arcpy.GetParameterAsText(1)
arcpy.management.ApplySymbologyFromLayer(in_fc,in_lyrx)
There is currently no direct connection between your script and the map itself. If you want to see updates onscreen, you should examine the arcpy.ma module. If there script is being run in the correct location with an open project using 'Current' as the project, then the map will be automatically refreshed in the newest version of PRO
Dan. I took a look at the arcpy.mp help (I think you meant mp, not ma?) and added a map parameter but I'm still missing something. The script below runs but again I don't see the symbology update. Thanks for the help!
ApplySymbologyFromLayer help topic suggests it should work... with the usual warnings and exclusions you may need to print the in_fc since it should be a layer in the project. They sadly, only give code samples for *.lyr files so I am not sure whether they mean 'layers' or 'layer' if you catch my drift and different emphasis on the term 'layer'
Thanks Dan. Yea, I catch your drift on layer/layers. I'll keep searching for a solution and post when I figure it out. For the time it is a bit maddening.
In your code, you are looping through the layers in a map, but you aren't doing anything to any of the layers when you loop through them. After you loop through them, you apply symbology to in_fc. What is in_fc, exactly? The variable naming makes me think it is a feature class and not a layer.
Joshua. The name I use "in_fc" indicates I'm picking a feature class but the data type in the tool is "Layer" (I also tried "Feature Layer") and I'm picking one of the layers in the map. I just loop through the layers to check that I have the right map and a layer is found matching the "in_fc" parameter.
Thanks for the suggestion.
If you hard-wire the parameter values and run the code from the interactive Python window, does it work for you?
I'm not quite sure how this differs from your original script, but this works for me:
my_lyr = 'qs' # the feature layer name
lyr_file = r'C:\junk\mylyr.lyrx' # the symbology layer file
arcpy.ApplySymbologyFromLayer_management(my_lyr,lyr_file) # apply symbology
dkwiens, are you running your code from the interactive Python window/console or a script tool? I think the OP is wanting to run it from a script tool and that is where the issue is arising.