Tool Crashes Pro when it reachesarcpy.management.MatchLayerSymbologyToAStyle()

399
6
03-19-2021 10:35 AM
by Anonymous User
Not applicable

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:

import arcpy

'''Set Parameters'''
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)[0]
lyr = m.listLayers(retail_layer)[0]

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")

 

Tags (3)
0 Kudos
6 Replies
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
0 Kudos
by Anonymous User
Not applicable

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.

0 Kudos
DanPatterson
MVP Esteemed Contributor

The crashes are probably the result of putting the application in an unstable state.  There are warnings in the CIM introduction

Python CIM access—ArcGIS Pro | Documentation

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.


... sort of retired...
0 Kudos
by Anonymous User
Not applicable

Thanks again Dan.

I think it has to do with the tool. I removed any cim related info and the tool still crashed.

0 Kudos
JeffK
by MVP Regular Contributor
MVP Regular Contributor

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?

by Anonymous User
Not applicable

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.

0 Kudos