I've been working on a geoprocessing script that will use the Match Symbology to A Style Tool. Unfortunatley every time the script reaches the line where I call the tool, Pro crashes.
Interestingly, if I use the same line of code in the python window it works correctly. Anyone else run into this issue before?
Here is the code up to that point:
map_name = arcpy.GetParameterAsText(0)
retail_layer = arcpy.GetParameterAsText(1)
symbol_param = arcpy.GetParameterAsText(2)
label_opt = arcpy.GetParameterAsText(3)
p = arcpy.mp.ArcGISProject('CURRENT')
m = p.listMaps(map_name)
lyr = m.listLayers(retail_layer)
rows = arcpy.SearchCursor(lyr)
names = [row.Name for row in rows]
'''Update the layer to unique values by name''
arcpy.management.MatchLayerSymbologyToAStyle(lyr, "$feature.ChainName", r"C:\Desktop\Logos.stylx")
is your script attached to a tool in arctoolbox when you are running it?, because you are using 'CURRENT' as the project. That is why it works in the python window. Toss in a few print statements to catch the name of the project (p) and the lyr name to make sure they are correct
Thanks for the reply Dan. I need to access the project like that in order to interact with the CIM. There's a portion of the tool where symbols are resized based on other parameters so unless there is a resize tool I believe I need to get into it that way.
I did try removing that portion of the script so that it was just running the Match Symbology to a Style Tool via the script and that still caused the program to crash.
* EDIT: I just tried adding in a portion to update the renderer of the layer prior to the Match Symbology tool. It still crashed.
The crashes are probably the result of putting the application in an unstable state. There are warnings in the CIM introduction
and guidance as to what should and should not be done. Unless you can narrow down you case so it fits within the boundaries of what is permissable in the guidelines then what you want to do may not be possible at this time.
This tool doesn't seem to have the standalone script syntax arcpy.MatchLayerSymbologyToAStyle_management() that the other tools have and the example (arcpy.management.MatchLayerSymbologyToAStyle() ) is for immediate mode so I wonder- is there a standalone syntax for the tool?
Thanks for the reply Jeff. I noticed that as well. Tried to use the arcpy.MatchLayerSymbologyToAStyle_management() syntax hoping it might work but had no luck.
I also tried importing the arcpy.management module as DM and referncing that with DM.MatchLayerSymbologyToAStyle() but had no luck with that either.