make a feature layer and change his color

1859
4
07-26-2017 04:33 AM
JohannesRuban
New Contributor

Hello, i have trouble with ArcGIS Pro and arcpy.

I want to make a feature layer, change his color and finally add him to the current Map

My Problem is, this Syntax work in Python Window in ArcGIS Pro, but not in my selfmade Tool.

Can someone help me.

lyr = arcpy.MakeFeatureLayer_management(r"C:\ArcGIS\Projects\Geologie\local_scene.gdb\aussrtm_Seligenstadt","test")
aprx = arcpy.mp.ArcGISProject("CURRENT")

for m in aprx.listMaps():
        for lyr in m.listLayers():
            if lyr.name == "test":
                sym = lyr.symbology
                sym.renderer.symbol.color = {'RGB': [10, 10, 10, 255]}
                lyr.symbology = sym‍‍‍‍‍‍‍‍‍
0 Kudos
4 Replies
RandyBurton
MVP Regular Contributor

Can you show how you were trying to implement this code in your tool?

0 Kudos
JohannesRuban
New Contributor

I creates a Polygon with geometry and safe him in this GDB:

C:\ArcGIS\Projects\Geologie\local_scene.gdb\aussrtm_Seligenstadt

Than I want make the feature class "aussrtm_Seligenstadt" to a feature Layer and change his Color. The Source Code works he have no errors or faults.

I think the problem: he creates the layer in the map after the tool is finished,

This dosn't  lyr.name == "test" work because the layer is in the map only after the tool is finished not during the tool is running

He creates the layer in the tool and insert not until the end of tool.

0 Kudos
JohnYaist1
Esri Contributor

JohannesRuban - I'm testing this out with Pro 2.0 right now. I see that this code works in the Python window and with a stand alone script. Looking into what happens when implemented as a script tool. I'll follow up with what I find. 

JohnYaist1
Esri Contributor

Hi Johannes Ruban‌ - I'm not sure how you implemented the script tool, but I've attached a zipped Pro package with 2 different script tools implementing a symbology change on a layer.  Worked with some colleagues and we saw they same that the implementation in your example didn't work. The script tool labeled Layer Color Changer2 in the project did work at Pro 2.0. Let me know if you see the same thing.

0 Kudos