ArcGIS Pro 1.41 Python script - what am I missing??

2196
16
02-17-2017 12:51 PM
RyanMcCluskey1
New Contributor

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)

0 Kudos
16 Replies
DanPatterson_Retired
MVP Emeritus

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

0 Kudos
RyanMcCluskey1
New Contributor

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!

0 Kudos
DanPatterson_Retired
MVP Emeritus

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'

0 Kudos
RyanMcCluskey1
New Contributor

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.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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.

0 Kudos
RyanMcCluskey1
New Contributor

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.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you hard-wire the parameter values and run the code from the interactive Python window, does it work for you?

0 Kudos
DarrenWiens2
MVP Honored Contributor

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‍‍‍‍‍‍‍‍‍‍
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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.

0 Kudos